Parsing multiple tags with no root in nokogiri

David N. Welton Source

I'm looking to do something like this:

fragment = parse("<p></p> <p></p>")
another_node.add_child(fragment)

But so far I haven't found anything that does the job - everything wants one root node with multiple children. Any ideas about how to accomplish this? It doesn't seem like it's that odd a request, and I feel like I must be missing something.

rubyxmlnokogiri

Answers

answered 7 years ago pguardiario #1

This works:

fragment = Nokogiri::HTML.fragment("<p></p> <p></p>")
another_node = Nokogiri::HTML.fragment("<div></div>")
another_node.add_child(fragment)

comments powered by Disqus