Skip to content

Instantly share code, notes, and snippets.

@rafaelrpbelo
Created January 12, 2016 13:58
Show Gist options
  • Save rafaelrpbelo/5aab7a578c1f6bdcc8fa to your computer and use it in GitHub Desktop.
Save rafaelrpbelo/5aab7a578c1f6bdcc8fa to your computer and use it in GitHub Desktop.
Example to build a xml document using Nokogiri::XML::Builder
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)
@rafaelrpbelo
Copy link
Author

The condition in the line 10 is to show when a condition to add a fragment xml have fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment