I am looking to utilize javascript to extract data from an XML file that has been loaded into a webpage.
Below is the XML file (a.xml) that I am working with.
a.xml
<?xml version="1.0"?>
<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:26]]></Time>
<TimeTick>1530810986</TimeTick>
<NodeArgs eType="User" icon="5" nRep="10" status="Passed" >
<Disp><![CDATA[GetDataTable - Successful]]></Disp>
</NodeArgs>
</Step>
I am interested in accessing specific nodes within the XML using javascript. In particular, I want to access the Time node after accessing the Step node.
Below is the index.html page where I intend to load the XML data:
index.html
<html>
<head>
<title>Report</title>
<style></style>
</head>
<body>
<p>Results of <b>Test cases</b> </p>
<div id="books"></div>
</body>
<script>
var oXHR = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
var testcase_Number = 0;
var endOfTest= 0;
function reportStatus() {
if (oXHR.readyState == 4)
showTheList(this.responseXML);
}
oXHR.onreadystatechange = reportStatus;
oXHR.open("GET", "a.xml", true);
oXHR.send();
function showTheList(xml) {
var divBooks = document.getElementById('books');
var Book_List = xml.getElementsByTagName('Step');
var divLeft = document.createElement('div');
divLeft.className = 'col1';
for (var i = 0; i < Book_List.length; i++) {
divLeft.innerHTML=Book_List[i].getChildElementsByTagName("Time")[0].nodeValue;
divBooks.appendChild(divLeft);
}
};
</script>
</html>
In the code above, the goal is to access the Time subnode under the Step node. Arrays are used as the XML file contains numerous Step subnodes, and I need to access the Time subnodes under each one of them.
Thank you for any assistance.