What is XPath in XML
In this article I am going to tell about XPath in XML.
Definition
XPath (XML Path Language) is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. XPath was defined by the World Wide Web Consortium (W3C).
- XPath is a syntax for defining parts of an XML document
- XPath uses path expressions to navigate in XML documents
- XPath contains a library of standard functions
- XPath is a major element in XSLT
- XPath is a W3C recommendation
XPath uses path expressions to select nodes or node-set in XML document. These path expressions look very much like the expressions you see when you work with a computer file system. XPath includes over hundred built-in functions. These are numeric values, date & time comparison, string values, sequence manipulation and more.
Example
<html>
<body>
<script type="text/javascript">
window.XMLHttpRequest
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.open("GET","list.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("Bike");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("Model")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
|
Link File
<?xml version= "1.0"?>
<inventory>
<bikes>
<model>Mountain Bike
<price>$220.00 </price>
</model>
<model>Cruiser Bike
<price>$180.00 </price>
</model>
</bikes>
</inventory>
|
Output
You may read more articles about XML here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here