Sunday, 29 September 2013

Unable to get contents of a tag of in xml file using javascript

Unable to get contents of a tag of in xml file using javascript

I have an xml file channels.xml containing something like this.
<StreamingChannelList xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<StreamingChannel>
<Source xmlns:a="http://schemas.datacontract.org/2004/07">
<a:directUrl>
rtsp://10.232.15.90/PSIA/Streaming/Channels/F36AFF8A-79A0-4C80-BED7-4EF795B4EDB0
</a:directUrl>
</Source>
</StreamingChannel>
</StreamingChannelList>
I need to get content of a:directUrl tag and i wrote following javascript
but unable to get the tag content.can anybody tell me what's wrong in the
code(specially last 4 lines)? FYI :using Safari browser on windows
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","channels.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var StreamingChannel=xmlDoc.getElementsByTagName("StreamingChannel");
var Source=StreamingChannel[0].getElementsByTagName("Source");
var directUrl=Source[0].getElementsByTagName("a:directUrl");
document.write("<td>"+directUrl[0].childNodes[0].nodeValue+"</td>");

No comments:

Post a Comment