Thursday, June 7, 2007

Parsing XML String To XML Using JavaScript

This Program Convert The XML String To XML
<html>
<body>
<script type="text/javascript">
var x;var xmlObj
var t="<NewDataSet>"
t+="<TestDTag>"
t+="<TestDate>06/07/2007</TestDate>"
t+="</TestDTag>"
t+="<TestDTag>"
t+="<TestDate>06/06/2007</TestDate>"
t+="</TestDTag>"
t+="<TestDTag>"
t+="<TestDate>06/05/2007</TestDate>"
t+="</TestDTag>"
t+="<TestDTag>"
t+="<TestDate>06/04/2007</TestDate>"
t+="</TestDTag>"
t+="<TestDTag>"
t+="<TestDate>06/03/2007</TestDate>"
t+="</TestDTag>"
t+="</NewDataSet>";
if (window.ActiveXObject)
{
xmlObj=new ActiveXObject("Microsoft.XMLDOM");
xmlObj.async="false";
xmlObj.loadXML(t);
}

if(xmlObj.documentElement != null)
{
var data = xmlObj.documentElement;
var Adate = xmlObj.documentElement.getElementsByTagName('TestDate');
for (i=0;i<=Adate.length-1;i++)
{
document.write(i+"th ChildElement -->"+data.childNodes[i].childNodes[0].nodeTypedValue+"<br>");
}
}
</script>
</body>
</html>


IE Supported



No comments:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.