Re: Xpath query of XPathResult?

"hairbo" <[email protected]> 5 Jun 2006 08:14:24 -0700
Newsgroups gmane.comp.mozilla.devel.xml
Organization http://groups.google.com
Message-ID <[email protected]>
The need is because I want to be able to grab arbitrary XML via Xpath
in one section of code, and then requery that subset via Xpath in
another, unrelated section of code.  You're right that if all the code
was together in one function, this would be unnecessary, but the code
is disconnected.  I also want to have just one way of accessing any Xml
client-side, and the way I want to do it is with Xpath.



Martin Honnen wrote:
> hairbo wrote:
>
> > As for Mozilla, I found a workaround that isn't too ugly.  I do the
> > following:
> >
> > var xmlString = new
> > XMLSerializer().serializeToString(result.iterateNext());
> > var xmlDoc = new DOMParser().parseFromString(xmlString, "text/xml");
> >
> > The first line takes the result of the XpathResult ("result"), and
> > serializes it to a string.  The next line takes that string of XML and
> > converts it into an XmlDocument, which I can then re-query.
>
> I am not sure I understand the need for that approach. The iterateNext
> function gives you a DOM node, if you want to make that DOM node the
> context node of another XPath evaluation then you can simply do
>    var node = result.iterateNext();
>    if (node != null) {
>      var secondResult = node.ownerDocument.evaluate(
>        'xpathexpression goes here',
>        node,
>        null,
>        0,
>        null
>      );
> 
> -- 
> 
> 	Martin Honnen
> 	http://JavaScript.FAQTs.com/