Re: Xpath query of XPathResult?
"hairbo" <[email protected]> 5 Jun 2006 07:43:13 -0700
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <[email protected]> |
Martin,
It turns out you're right, at least on the JS side.
I've used MSXML on the server side, and I recall being able to re-query
the returned node with Xpath, but it's possible that somebody else was
doing some kind of manipulation of the returned object to make it
accessible by Xpath again.
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.
The only issue for me is that the "serializeToString" function returns
that containing node, when I really only want the children. So, I'll
need to strip away the containing node before calling
"parseFromString".
This all may seem a bit ugly, but this code is intended to live under
the hood, and I really find Xpath the most elegant and simple way of
accessing nodes in XML, so the under-the-hood code ends up fairly ugly,
but the code accessing these functions ends up pretty clean.
Martin Honnen wrote:
> hairbo wrote:
>
>
> > The MSXML parser seems to have no difficulty running an xpath query on
> > a returned nodeset, so I'm struggling to see why this appears to be so
> > difficult in Mozilla's implementation.
>
> Could you show what kind of MSXML code use you have?
> In my understanding you can call selectNodes/selectSingleNode with a
> single node as the context node. I don't know of a way to run an XPath
> on a complete nodeset.
> And with Mozilla's XPath API it is possible to pass in a single node as
> the context node too so I am not sure what you think MSXML can do that
> Mozilla's API can't do.
>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/