Re: document.evaluate, 2nd parameter, I don't get it
"Nickolay Ponomarev" <[email protected]> Fri, 17 Aug 2007 15:07:31 +0400
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Message-ID | <[email protected]> |
On 8/17/07, [email protected] <[email protected]> wrote: > I'd like to get all the links inside all the subsections of the page: > http://www.hardware.fr > The subsections are named 'cat1', 'cat2', etc, up to 'cat16'. > [...] > allLinks = document.evaluate('//a[@href]', > document.getElementById('cat16'), null, [...] > returns all the links of the page, not the links of the 'cat16' > element. Why ? > > Ie, it has the same results than > allLinks = document.evaluate('//a[@href]', document, null, > XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); > See http://www.w3.org/TR/xpath#path-abbrev "//para selects all the para descendants of the document root and thus selects all para elements in the same document as the context node" ".//para selects the para element descendants of the context node" The "context node" is what you specify in the second parameter to document.evaluate. This means you need .//a[@href] > According to this page: > http://diveintogreasemonkey.org/patterns/match-attribute.html > it shouldn't: > Quote: > "The second parameter can be any element, and the XPath query will > only return nodes that are children of that element. So if you already > have a reference to an element (say, from document.getElementById or a > member of a document.getElementsByTagName array), you can restrict the > query to search only children of that element." > As far as I can see, this is wrong. Please let Mark know about it. Nickolay