Jump to content

xpath on multiple files


johnspiderwebb

Recommended Posts

I want to be able to get the value of an xpath element for multiple xml files.I understand how to do this for one named file...<html><body><script type="text/javascript">function loadXMLDoc(dname){if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); }else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xhttp.open("GET",dname,false);xhttp.send("");return xhttp.responseXML;}fname="books.xml";xml=loadXMLDoc(fname);path="/bookstore/book/title"// code for IEif (window.ActiveXObject){var nodes=xml.selectNodes(path);for (i=0;i<nodes.length;i++) { document.write(fname+","+nodes.childNodes[0].nodeValue); document.write("<br />"); }}// code for Mozilla, Firefox, Opera, etc.else if (document.implementation && document.implementation.createDocument){var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);var result=nodes.iterateNext();while (result) { document.write(fname+","+result.childNodes[0].nodeValue); document.write("<br />"); result=nodes.iterateNext(); }}</script></body></html>However, I want to query all xml files in a folder, and have no idea how to get the list of files.....

Link to comment
Share on other sites

If the folder can be viewed in the browser (as opposed to returning 403: Forbidden), you can read the index page in the same way you read an XML file, and get the list from there. This of course assumes the folder to query is separate from the one the HTML file is in.BTW,

if (window.ActiveXObject){var nodes=xml.selectNodes(path);

should probably be

if (xml.selectNodes){var nodes=xml.selectNodes(path);

Since you never know when IE might drop that method, or if other browsers might implement it.

Link to comment
Share on other sites

If the folder can be viewed in the browser (as opposed to returning 403: Forbidden), you can read the index page in the same way you read an XML file, and get the list from there. This of course assumes the folder to query is separate from the one the HTML file is in.BTW,
if (window.ActiveXObject){var nodes=xml.selectNodes(path);

should probably be

if (xml.selectNodes){var nodes=xml.selectNodes(path);

Since you never know when IE might drop that method, or if other browsers might implement it.

Thank you.I'll try that.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...