Below is the XML format I am working with:
<Result>
<system>
<STATIC>
<Tag1>2015-10-29T02:02:38-08:00</Tag1>
<Tag2>264000000</Tag2>
<Tag3>32696320</Tag3>
</STATIC>
</system>
</Result>
I attempted to parse the child elements using the code below:
if(window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(res,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(res);
}
var result=xmlDoc.getElementsByTagName("Result"); // Result child
For the system child, I tried:
var system=result[0].childNodes[0];
However, when I attempted to get the <system>
tag's child, an error occurred:
var staticResp=system[0].childNodes[0];
Error : Uncaught TypeError: Cannot read property 'childNodes' of undefined(…)
Could someone please assist me in retrieving the child of the <static>
tag and its value using the tag name?
Thank you for the prompt replies.
After receiving the above XML data in an AJAX response, I noticed some special characters like
after the system tag.
It seems that the proposed solutions may not work for my case.
Can anyone offer assistance on how to ignore these special characters and successfully parse the string?
Here is the captured XML:
<Result><system> <STATIC> <Tag1>2015-10-29T02:02:38-08:00</Tag1> <Tag2>264000000</Tag2> <Tag3>32696320</Tag3></STATIC> </system></Result>