Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashaninBenjamin/3984082b4a43649a9160f4e3b3fff4d8 to your computer and use it in GitHub Desktop.
Save ashaninBenjamin/3984082b4a43649a9160f4e3b3fff4d8 to your computer and use it in GitHub Desktop.
# The way to insert some xml into building xml with correct indents
builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
xml.Batch do
xml.Count 1
end
end
batch_xml_element = builder.doc.at('Batch')
xml_text = '<Element><One>1</One><Two>2</Two></Element>'
xml_element = Nokogiri::XML(xml_text, &:noblanks).root
batch_xml_element.add_child(xml_element)
builder.to_xml
# <?xml version="1.0" encoding="UTF-8"?>
# <Batch>
# <Count>1</Count>
# <Element>
# <One>1</One>
# <Two>2</Two>
# </Element>
# </Batch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment