English

Navigation
Powered by Squarespace
Foobaruy mwe

Buy my book on <a href="lulu.com">lula</a>

« Efforts for our climate | Main | Determine Language of Text »
Freitag
Sep042009

Hpricot and Namespaces/XPath

Until today we were happy users of Hpricot (0.8.1) . Easy to use, nice API, fast (enough)... but today we had to move a project over to Nokogiri.Why? Hpricot does not support XPath with namespaces. Worse: it does not even complain when you use a namespaced XPath query. It just keeps telling you that your XPath ended up in Nirvana and that there is no result."Hey pal, you are using namespaces in XPath and i do not understand this" would have been a nice message.Since Hpricot does properly parse the namespaces, you can work around the problem using the at (aliased as %) method. But we need full XPath support hence the switch to Nokogiri.Some links i came across while researching the issue:

Reader Comments (2)

Is it just failing to work with namespaces properly, or does it ignore prefixes completely?

September 4, 2009 | Unregistered CommenterRobert Fischer

Hi Robert

It just did not work, the searches with XPath just did not return any result if the query contained the namespace more than once.

I.e.:
'/EAD:ead/EAD:eadheader/EAD:filedesc/EAD:titlestmt/EAD:titleproper'
Would return nothing while
'/EAD:ead/EAD:eadheader' did not return a single result.

BTW:
path = (hpricot / 'EAD:titleproper').first.xpath
nodes = hpricot / path
-> nodes is empty

September 9, 2009 | Unregistered Commenterpascal

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>