Created
January 12, 2016 13:58
-
-
Save rafaelrpbelo/5aab7a578c1f6bdcc8fa to your computer and use it in GitHub Desktop.
Example to build a xml document using Nokogiri::XML::Builder
This file contains 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
require 'nokogiri' | |
def add_xml(xml) | |
xml.send(:level, 'last') | |
end | |
builder = Nokogiri::XML::Builder.new do |xml| | |
xml.send(:level_1) do | |
xml.send(:level_2) do | |
add_xml(xml) if 1 == 2 | |
end | |
end | |
end | |
puts builder.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS | | |
Nokogiri::XML::Node::SaveOptions::FORMAT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The condition in the line 10 is to show when a condition to add a fragment xml have fail.