Freitag
Sep042009
Hpricot and Namespaces/XPath
Freitag, September 4, 2009 at 4:15PM
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?
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