Created
May 31, 2021 14:14
-
-
Save ashaninBenjamin/3984082b4a43649a9160f4e3b3fff4d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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