I have an XML document where some of the nodes have a .
in their name:
<com.site.blah>
<id>asdkjasd</id>
<com.site.testing>
<name>test</name>
</com.site.testing>
</com.site.blah>
If I try @doc.search("/*/id").first.xpath
, it returns /com.site.blah/id
, but if I then do: @doc.search("/com.site.blah/id").first.inspect
it returns nil
.
I want to be able to make an XPath query to select the name under com.site.testing
, but it keeps rejecting my queries.
Any ideas?
(I am using hpricot if it makes a difference)
Your XPath library is broken. An XPath name test is a QName (http://www.w3.org/TR/xpath/#NT-NameTest), which, after following the rabbit hole of EBNF, includes periods (http://www.w3.org/TR/REC-xml/#NT-NameChar). Report the error to the developers.
As a workaround, neither of the escape mechanisms mentioned in the comments are part of XPath, but you can try using a predicate to check the element name, like so:
/*[name(.) = 'com.site.blah']/id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With