Re: Node.prototype.selectNodes function problems

Lucky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xml
Organization Cox Communications
Message-ID <dmAie.16059$iU.2578@lakeread05>
[email protected] wrote:
> Okay, I've studied sarissa, it needs an array with namespaces and a
> binding function. I've tried this, in a quick and dirty solution, but
> the code below still doesn't work:
> 
> 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);
> 
>   doc._namespaces = {};
>   doc._namespaces["soap"] =
> "http://schemas.xmlsoap.org/soap/envelope/";
>   doc._namespaces["xsi"] = "http://www.w3.org/2001/XMLSchema-instance";
>   doc._namespaces["xsd"] = "http://www.w3.org/2001/XMLSchema";
> 
>   var nsRes2 = function(s)
>   {
>     return doc._namespaces[s];
>   }
> 
>   var xpRes = doc.evaluate(sExpr, this, nsRes2, 5, null);
> 
>   var res = [];
>   var item;
>   while (item = xpRes.iterateNext())
>     res.push(item); 
>   return res; 
> }
> 

// perhaps this could help:

Node.prototype.namespaceResolver = function(prefix) {
	swith(prefix){
		case 'soap': return 'http://schemas.xmlsoap.org/soap/envelope/';
		case 'xsi':  return 'http://www.w3.org/2001/XMLSchema-instance';
		case 'xsd':  return 'http://www.w3.org/2001/XMLSchema';
		case 'xul':  return 
'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
	}
	return null;
}
Document.prototype.selectNodes =
Node.prototype.selectNodes = function(xpath) {
	var nodes = document.evaluate(xpath,this,this.namespaceResolver,0,null);
	var nodelist = new Array();
	var node = nodes.iterateNext();
	while( node ){nodelist.push( node );node = nodes.iterateNext();}
	return nodelist;
}
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.