Nokogiri/Xpath namespace query?

All namespaces need to be registered when parsing. Nokogiri automatically registers namespaces on the root node. Any namespaces that are not on the root node you have to register yourself.

This should work: puts doc. Xpath('//dc:title', 'dc' => "URI") Alternately, you can remove namespaces altogether. Only do this if you are certain there will be no conflicting node names doc.

Remove_namespaces! Puts doc. Xpath('//title').

All namespaces need to be registered when parsing. Nokogiri automatically registers namespaces on the root node. Any namespaces that are not on the root node you have to register yourself.

This should work: puts doc. Xpath('//dc:title', 'dc' => "URI") Alternately, you can remove namespaces altogether. Only do this if you are certain there will be no conflicting node names.Doc.

Remove_namespaces! Puts doc. Xpath('//title').

Awesome worked perfectly, thanks! – Jamie Jan 14 at 12:35 +1 Yeah remove_namespaces FTW! – Eduardo Cobuci Jun 13 at 4:50 Thank you!

This is magic! – Jirapong Aug 31 at 1:55.

With properly registered prefix opf for 'idpf.org/2007/opf' namespace URI, and dc for 'URI', you need: /*/opf:metadata/dc:title Note: xmlns and xml are reserved prefixes that can't be bound to any other namespace URI than the built-in 'w3.org/2000/xmlns/' and 'w3.org/XML/1998/namespace'.

Didn't seem to work doc. Xpath('/*/opf:metadata/dc:title') # => "`evaluate': Undefined namespace prefix" – Jamie Jan 14 at 12:30 @Jamie: Did you actually read the answer? First sentence starts "With properly registered prefix"... – user357812 Jan 14 at 12:39 @Alejandro apologies I don't entirely understand is there a way to do it without the prefix for opf (except the way described in @mark-thomas answer), it'd be nice to do it in one xpath query.

– Jamie Jan 14 at 12:52 @Jamie: No problem. But it's important that you understand XML namespaces. This is one XPath expression.

You need to know the way that your XPath engine use for registering namespace. From @Mark Thomas answer, this seems to be accomplish by a second parameter to xpath() function... – user357812 Jan 14 at 13:03.

All namespaces need to be registered when parsing. Nokogiri automatically registers namespaces on the root node. Any namespaces that are not on the root node you have to register yourself.

This should work.

With properly registered prefix opf for 'idpf.org/2007/opf' namespace URI, and dc for 'URI', you need.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions