I think I set up the namespace resolver right,
var nodes=xml.evaluate(path, //xpathExpression
xml, //contextNode
NSResolver, //namespaceResolver
XPathResult.ANY_TYPE, //resultType
null //result
);
and I think I am setting path correctly, (Ive tried alot of variation here, pretty much anything that might work)
path="/";
but the nodes.iterateNext() seems to be telling me I did something wrong :
firebug output : nodes : [object XPathResult] length : undefined
the x and xml object are good though, because I can see them and the xml in firebug. If you use my code, Im just testing in chrome so if youre using IE you may have a whole other can of worms. :)
Heres the xml (sanitized version)
<dataset xmlns="http://stub.test.data1" xmlns:xs="http://another.stub.test.moredata">
<!--
<dataset
xmlns="http://stub.test.data1"
xmlns:xs="http://another.stub.test.moredata"
xs:schemaLocation="http://yet.more.stub.test.data/xmldata.xsd"
>
-->
<metadata>
<item name="a" type="xs:string" length="92"/>
<item name="b" type="xs:string" length="50"/>
<item name="c" type="xs:short" precision="1"/>
<item name="d" type="xs:string" length="66"/>
<item name="e" type="xs:string" length="26"/>
<item name="f" type="xs:string" length="6"/>
<item name="g" type="xs:string" length="264"/>
<item name="h" type="xs:double" precision="2"/>
<item name="i" type="xs:string" length="22"/>
<item name="j" type="xs:date"/>
<item name="k" type="xs:date"/>
<item name="l" type="xs:string" length="16"/>
<item name="m" type="xs:short" precision="1"/>
<item name="n" type="xs:short" precision="1"/>
<item name="o" type="xs:string" length="50"/>
</metadata>
<data>
<row>
<value>someData1</value>
<value>someData2</value>
<value>someData3</value>
<value>someData4</value>
<value>someData5</value>
<value>someData6</value>
<value>someData7</value>
<value>someData8</value>
<value>someData9</value>
<value>someData10</value>
<value>someData11</value>
<value>someData12</value>
<value>someData13</value>
<value>someData14</value>
<value>someData15</value>
</row>
</data>
</dataset>
And heres the javascript :
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//initializes the request
xhttp.open("GET",dname,false);//method, url, optional async defaults to true
try {xhttp.responseType="msxml-document"} catch(err) {
console.log('hey, an error occured');
} // Helping IE
xhttp.send("");//send the request. Does not return till the response is returned (due to false above)
return xhttp;
}
function NSResolver(nsPrefix) {
console.log("nsPrefix : " + nsPrefix);
if(nsPrefix == "xs") {
return "http://www.w3.org/2001/XMLSchema-instance";
}
}
function displayNodes() {
// code for IE
if (window.ActiveXObject || xhttp.responseType=="msxml-document")
{
console.log('code for IE');
console.log('path=' + path);
xml.setProperty("SelectionLanguage","XPath");
nodes=xml.selectNodes(path);
for (i=0;i<nodes.length;i++)
{
document.write(nodes[i].childNodes[0].nodeValue);
document.write("<br>");
}
}
// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
console.log('code for chr / ff / op');
console.log('path=' + path);
//docs : http://help.dottoro.com/ljruhkuj.php
var nodes=xml.evaluate(path, //xpathExpression
xml, //contextNode
NSResolver, //namespaceResolver
XPathResult.ANY_TYPE, //resultType
null //result
);
console.log("nodes : " + nodes + " length : " + nodes.length);
var result=nodes.iterateNext();
while (result)
{
document.write(result.childNodes[0].nodeValue);
document.write("<br>");
result=nodes.iterateNext();
}
}
document.write('shit should have displayed by now');
}
path="/";
function reload() {
x=loadXMLDoc("testxml.xml"); //x is now a XMLHttpRequest object
xml=x.responseXML; //xml is now a response to the request, or null if it failed
displayNodes();
console.log("x (XMLHTTPRequest Object) : " + x);
console.log("xml (XMLHTTPRequest.responseXML) : " + xml);
}
reload();