How To Load An Xml File Into A Html Page Using Java Script And Parse Data From It Using Xpath
Hi i am using java script to extract data from xml file. The below given is my index.html index.html Report
Solution 1:
Thanks everyone for the help, Finally was able to do it..below given is the answer to any folks who come here in desperation. Thanks
index.html
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
showResult(xhttp.responseXML);
}
};
xhttp.open("GET", "a.xml", true);
xhttp.send();
function showResult(xml) {
var txt = "";
path = "//Step/Time"
if (xml.evaluate) {
var nodes = xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result = nodes.iterateNext();
while (result) {
txt += result.childNodes[0].nodeValue + "<br>";
result = nodes.iterateNext();
}
// Code For Internet Explorer
} else if (window.ActiveXObject || xhttp.responseType == "msxml-document") {
xml.setProperty("SelectionLanguage", "XPath");
nodes = xml.selectNodes(path);
for (i = 0; i < nodes.length; i++) {
txt += nodes[i].childNodes[0].nodeValue + "<br>";
}
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
a.xml
<?xml version="1.0" encoding="UTF-8"?>
<Steps>
<Step rID="T6">
<Obj ><![CDATA[Get Data Table - Passed]]></Obj>
<Details ><![CDATA[]]></Details>
<Time><![CDATA[7/5/2018 - 13:16:26]]></Time>
<TimeTick>1530810986</TimeTick>
<NodeArgs eType="User" icon="5" nRep="9" >
<Disp><![CDATA[Get Data Table - Passed]]></Disp>
</NodeArgs>
</Step>
<Step rID="T7">
<Obj ><![CDATA[GetDataTable - Successful]]></Obj>
<Details ><![CDATA[Toral Row get:65534]]></Details>
<Time><![CDATA[7/5/2018 - 13:16:27]]></Time>
<TimeTick>1530810986</TimeTick>
<NodeArgs eType="User" icon="5" nRep="10" status="Passed" >
<Disp><![CDATA[GetDataTable - Successful]]></Disp>
</NodeArgs>
</Step>
</Steps>
Post a Comment for "How To Load An Xml File Into A Html Page Using Java Script And Parse Data From It Using Xpath"