Hi Mike,
Is it possible to create both the fragment and the root document using builder? I modified your example slightly but I’m getting the error message, “Document already has a root node”.
Liz
require 'rubygems'
require "nokogiri"
# source from Mike Dalessio
doc = Nokogiri::XML::Builder.new do
root {
div "a fragment"
div "is just a document subtree"
div "with multiple roots"
div "also known as a nodeset"
}
end.doc
fragment = doc.root.children # bonus points: use the results of an xpath or css query
#doc2 = Nokogiri::XML "<root2></root2>"
doc2 = Nokogiri::XML::Builder.new do
root2 {
div "another node"
}
end.doc2
--
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.
Hi Mike,
Is it possible to create both the fragment and the root document using builder? I modified your example slightly but I’m getting the error message, “Document already has a root node”.
Liz
require 'rubygems'
require "nokogiri"
# source from Mike Dalessio
doc = Nokogiri::XML::Builder.new do
root {
div "a fragment"
div "is just a document subtree"
div "with multiple roots"
div "also known as a nodeset"
}
end.doc
fragment = doc.root.children # bonus points: use the results of an xpath or css query
#doc2 = Nokogiri::XML "<root2></root2>"
doc2 = Nokogiri::XML::Builder.new do
root2 {
div "another node"
}
end.doc2
doc2.root.inner_html = fragment
puts doc2.to_xml
doc2 = Nokogiri::XML::Builder.new doroot2 {div "another node"}end.doc
doc2.root.children.first.after fragmentputs doc2.to_xml
# => <?xml version="1.0"?># <root2>
# <div>another node</div>
# <div>a fragment</div># <div>is just a document subtree</div># <div>with multiple roots</div># <div>also known as a nodeset</div># </root2>
Hi Mike,
I’m running Aptana Radrails(build: 2.0.5.1278709071) with Ruby 1.87-p302 and Nokogiri 1.4.4.1 on windows. I’m not sure how to find the version of libxml2. I’ll see if I can figure out how to add the –v switch. If I remember correctly I think I went with Ruby 1.87 instead of Ruby 1.9 because I couldn’t get the ruby-oci8(needed for ActiveRecord/Oracle) stuff working. Maybe I’ll give that another try.
Liz
From: nokogi...@googlegroups.com [mailto:nokogi...@googlegroups.com] On Behalf Of Mike Dalessio
Sent: Monday, December 20, 2010 6:07 AM
To: nokogi...@googlegroups.com