Hey all, I'm having trouble using dynamic node names when creating an
XML document in Nokogiri.
For a static node name I would do the following:
xml.myNodeName "This is my node text"
But what if I want to use a dynamic name for my node? I would assume
it would be similar to the example below but I haven't been able to
get it to work... Any ideas?
for item in myItems
xml[item.itemId] item.itemText
end # for each item
node_names = ["foo", "bar", "bazz"]builder = Nokogiri::XML::Builder.new do |xml|xml.root donode_names.each { |name| xml.send name, "some content" }endendputs builder.to_xml# => <?xml version="1.0"?># <root># <foo>some content</foo># <bar>some content</bar># <bazz>some content</bazz># </root>
builder = Nokogiri::XML::Builder.new do |xml|xml.root donode_names.each { |name| xml.send "#{name}_", "some content" }endend
I appreciate any assistance you can give, thanks!
Spencer
--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To post to this group, send email to nokogi...@googlegroups.com.
To unsubscribe from this group, send email to nokogiri-tal...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nokogiri-talk?hl=en.