-
-
Save flavorjones/113210 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
# | |
# must set the document root node. one line change to original: | |
# | |
n = Nokogiri::XML::Node.new('root', Nokogiri::XML::Document.new) | |
n.document.root = n | |
n << Nokogiri::XML::Node.new('child', n.document) | |
n << (c = Nokogiri::XML::Node.new('child', n.document)) | |
c.default_namespace = 'foo:bar' | |
# | |
# but it's clearer like this: | |
# | |
doc = Nokogiri::XML::Document.new | |
doc.root = (n = Nokogiri::XML::Node.new('root', doc)) | |
n << Nokogiri::XML::Node.new('child', doc) | |
n << (c = Nokogiri::XML::Node.new('child', doc)) | |
c.default_namespace = 'http://foo.com/' | |
puts doc | |
puts n.search('child', {'xmlns' => 'http://foo.com/'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment