Bulk adding elements?

2 views
Skip to first unread message

viatropos

unread,
Sep 30, 2009, 12:15:18 AM9/30/09
to nokogiri-talk
How would you do something like the following for adding a small tree
of xml nodes to a parent node?

xml = Nokogiri::XML(<<-eoxml) { |c| c.noblanks }
<root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
<awesome/>
</root>
eoxml

I would like to be able to do something like this:

node = Nokogiri::XML::Node(<<-eoxml) { |c| c.noblanks }
<aNode>
<subNode>
<subSubNode attributeA="value"/>
<subSubNode/>
</subNode>
</aNode>
eoxml

parent.add_child(node)

Is that possible? Or what is the best way to accomplish that,
assuming the "parent" variable is a parent 3 elements deep or whatever
(aka it isn't the document)?

Thanks so much for your help,
Lance

Aaron Patterson

unread,
Sep 30, 2009, 11:43:34 AM9/30/09
to nokogi...@googlegroups.com

What have you tried so far? I know we've solved a problem very
similar to this in a different thread.

--
Aaron Patterson
http://tenderlovemaking.com/

Reply all
Reply to author
Forward
0 new messages