문제

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top