Re: Node.prototype.selectNodes function problems
Martin Honnen <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Organization | Liberty Development |
| Message-ID | <[email protected]> |
[email protected] wrote: > I'm trying to create a javascript application that uses data returned > from a (ASP.NET) webservice. I want a cross-browser (IE/Mozilla) > solution for this. The webservice data loads fine into a document, but > then I want to use XPath to select particular nodes in this document. > IE has a selectNodes function for this, so I want to create this > function for Mozilla as well. I have the following for Mozilla: > > Node.prototype.selectNodes = function(sExpr) > { > //DOCUMENT_NODE = 9 > var doc = this.nodeType == 9 ? this : this.ownerDocument; > > var nsRes = doc.createNSResolver(this.nodeType == 9 ? > this.documentElement : this); > > var xpRes = doc.evaluate(sExpr, this, nsRes, 5, null); > > var res = []; > var item; > while (item = xpRes.iterateNext()) > res.push(item); > return res; > } > > When I use the Mozilla javascript debugger on this piece of code and > the doc.evaluate statement has been executed, the xpRes variable > contains a lot of XPathExceptions, with the following value: "The > expression cannot be converted to return the specified type." How does the XPath expression look, how does the XML document look, which node are you calling the method on? -- Martin Honnen http://JavaScript.FAQTs.com/