I want to use javascript to get information from a xml file loaded into a webpage.
The below given is the xmlfile(a.xml) i am using.
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 want to access nodes under a specific node in xml using java script? That is i want to access Time node after i access step node. And the below given is the index.html page to which i want 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) // REQUEST COMPLETED.
showTheList(this.responseXML); // ALL SET. NOW SHOW XML DATA.
}
oXHR.onreadystatechange = reportStatus;
oXHR.open("GET", "a.xml", true); // true = ASYNCHRONOUS REQUEST
//(DESIRABLE), false = SYNCHRONOUS REQUEST.
oXHR.send();
function showTheList(xml) {
var divBooks = document.getElementById('books'); // THE PARENT DIV.
var Book_List = xml.getElementsByTagName('Step'); // THE XML TAG NAME.
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 above code I am trying to access the Time subnode under the step node. and I have used arrays in the above example as the xml page i am using have lots of Step subnodes , and i want to access the Time subnodes under Step for each one of them.
thanks, Any help is appreciated