Re: XPath expression prefixes

Lucky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xml
Organization Cox Communications
Message-ID <bhTie.177$%Z2.29@lakeread08>
[email protected] wrote:
> <<Continued from yesterday>>
> 
> I finally have my selectNodes function working. The only problem is
> that I always have to use a prefix in my XPath expression, for example
> "//ws:MasterRow". This prefix causes problems in IE however. Can I use
> XPath in Mozilla on a Soap document without using prefixes in my XPath
> expression?
> 
> Node.prototype.selectNodes = function(sExpr)
> {
>   //DOCUMENT_NODE = 9
>   var doc = this.nodeType == 9 ? this : this.ownerDocument;
>   var nsRes = doc.createNSResolver(this.node­Type == 9 ?
> this.documentElement : this);
> 
>   var nsRes2 = function(s) {
>     return "http://myservice.com";
>   }
> 
>   var xpRes = doc.evaluate(sExpr, this, nsRes2, 5, null);
>   var res = [];
>   var item;
>   while (item = xpRes.iterateNext())
>     res.push (item); 
>   return res ; 
> }
> 
this is probably what you are seeking..
http://teamcon.com/pub/concepts/mozilla/xml.selectnodes.htm

please feel free to test this out as much as possible..
this is an updated portion of my cross-browser library :)


primary focus would be in the 3) + 4) samples..
they show how .protype(s) can be used to get a fuller IE model support

xmlDocument.setPropery('SelectionNamespaces','blah blah');

the XMLDocument.globalNamespaces is a nice concept as well.
but you would need to add them consistently for IE or
if you have a consistent loadXML( ), you could apply them there.
simply

xmldom.setProperty('SelectionNamespaces',XMLDocument.globalNamespaces.toString()); 

to get the xmlns:foo="bar" entries.

oh yea, and finally.. this version has not been marked up to allow for 
FULL cross browser support right now.
it has been marked up and focus was only on Moz/Fx browsers.
so you'd have to add in code to wire up a mock XMLDocument {} for IE, etc.

g'luck
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.