Re: Xpath query of XPathResult?

Martin Honnen <[email protected]> Thu, 08 Jun 2006 18:03:00 +0200
Newsgroups gmane.comp.mozilla.devel.xml
Organization Liberty Development
Message-ID <[email protected]>
hairbo wrote:

> First off, I was wrong about the result of "selectNodes".  In IE, it
> returns an array of XML elements that cannot be re-queried by Xpath.

You get a DOM node list not a JavaScript array. And right, you can't do 
an XPath query on the complete node list. But as pointed out, you can 
loop through the list and call selectNodes (or selectSingleNode) on each 
node so that way you can requery on each node.

> The same is true of Mozilla, so while the syntax is different in the
> two browsers, the results are the same.

Mozilla's XPath API gives you a node set in various form, either as a 
snapshot or as an iterator. Again you can't do an XPath on the complete 
result returned but you can certainly pass in each node you iterate over 
or the snapshot gives into the evaluate method as as the second argument.

> My goal *is* to be able to re-query the returned elements with Xpath,
> and in order to do that, I need to turn the returned xml element back
> into an xml document.

I don't understand that approach at all, why can't you call selectNodes 
on each node returned or use the evaluate method to pass in each node as 
the context node?
That is possible and makes much more sense in general as your attempt to 
convert a node back into a document blows up if you tried that with a 
text node or attribute node or comment node or processing instruction node.



> The only trouble is, I think, Safari and Opera do not offer Xpath
> support at this time.  Or, at the very least, I can find no evidence
> that they do.  So that's a bummer.

Opera 9 beta follows Mozilla to implement the W3C DOM Level 3 XPath API 
so with Opera 9 there will be XPath support.

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/