Reputation: 31380
I'd like to create several builders, with common tags, in order to have xml docs like :
<xml version="1.0"?>
<a_kind_of_root>
<!-- This part is common -->
<event_date>20100514</event_date>
<event_id>123</event_id>
<event_type>Conference</event_type>
<!-- This part is specific to the builder -->
<my_tag>some text</my_tag>
</a_kind_of_root>
</xml>
<xml version="1.0"?>
<another_kind_of_root>
<!-- This part is common -->
<event_date>20100514</event_date>
<event_id>123</event_id>
<event_type>Conference</event_type>
<!-- This part is specific to the builder -->
<my_other_tag>some integer</my_other_tag>
</another_kind_of_root>
</xml>
I don't know how to put the common part inside a Nokogiri::XML::Builder
Thanks
Upvotes: 0
Views: 330
Reputation:
You can pass your Builder to a method & have that method add your common event information:
def event_tags(xml, ev=Hash.new)
xml.event_date = ev[:date]
xml.event_id = ev[:id]
xml.event_type = ev[:type]
end
builder = Nokogiri::XML::Builder.new do |xml|
xml.root {
event_tags xml, :date => get_date, :id => get_id, :type => get_type
# blah blah
}
end
Upvotes: 1