Reputation: 3952
I have the following XML:
<body>
<hello xmlns='http://...'>
<world>yes</world>
</hello>
</body>
When I load that into a Nokogiri XML document, and call document.at_css "world"
, I receive nil
back. But when I remove the namespace for hello
, it works perfectly. I know I can call document.remove_namespaces!
, but why is it that it will not work with the namespace?
Upvotes: 3
Views: 685
Reputation: 11588
Because Nokogiri requires you to register the XML namespaces you are querying within (read more about XML Namespaces). But you should still be able to query the element if you specify its namespace when calling at_css
. To see the exact usage, check out the css
method documentation. It should end up looking something like this:
document.at_css "world", 'namespace_name' => 'namespace URI'
Upvotes: 1