What’s the purpose of the double slash in Hpricot?
doc.search("/html/body//p")
What’s the purpose of the double slash in Hpricot?
doc.search("/html/body//p")
Daniel W. wrote:
What’s the purpose of the double slash in Hpricot?
doc.search("/html/body//p")
Google for an XPath tutorial. // is XPathic for the “any descendant”
axis.
So the above matches any
(presumably the first) in the body of a
document.
The equivalent in XPath would be assert_xpath(’/html/body//p’). I don’t
know
how close Hpricot comes to XPath, which can do things like this:
assert_xpath “.//Statement[ last() - 1 ]”
That matches the second-to-last item called
However, REXML::XPath cannot handle common XHTML idioms…
Can’t we all just … get along?
A follow-up question:
“/” is supposed to be synonymous with Hpricot::Elem#search … is “//”
as well?
Phlip wrote:
Daniel W. wrote:
What’s the purpose of the double slash in Hpricot?
doc.search("/html/body//p")
Google for an XPath tutorial. // is XPathic for the “any descendant”
axis.
So the above matches any(presumably the first) in the body of a
document.The equivalent in XPath would be assert_xpath(’/html/body//p’). I don’t
know
how close Hpricot comes to XPath, which can do things like this:assert_xpath “.//Statement[ last() - 1 ]”
That matches the second-to-last item called
However, REXML::XPath cannot handle common XHTML idioms…
Can’t we all just … get along?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs