Enter XPath:   

Paragraph one

Paragraph two

Paragraph three

The HTML code for the box to the left.

        <textarea id="textBox" cols="50" rows="10" style="border: thin solid black"></textarea>
         <br />
         <p>Enter XPath:    <input id="inputValue" value="XPathHere" 
         type="text" width="150" style="border: solid thin black"/></p>
         <input type="button" value="Test XPath" onclick="doTest()" />
        <p>Paragraph one</p>
        <p id="two">Paragraph two</p>
        <p class="paraType">Paragraph three</p>
        <ul>
         <li>List item one</li>
         <li>List item two</li>
         <li>List item three</li>
        </ul>
        

Example XPath queries to try:



Importing XML and selecting nodes with XPath


<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;
}

var xml=loadXMLDoc("books.xml");

var path="/bookstore/book/title";

// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);

for (i=0;i<nodes.length;i++)
  {
  document.write(nodes[i].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(result.childNodes[0].nodeValue);
  document.write("<br />");
  result=nodes.iterateNext();
  }
}
</script>