anatar02
14 years agoContributor
Getting an undefined error in function
Hi All,
I am very new to TestComplete + javascript and began with developing a function which would help to retrieve the xml node value from test data of xml, but I am getting an error saying the "document" is undefined!!! But the same code is working well and fine in Browser!!!!! Someone please help me with this.. The sample code below for your review.
function getxml() {
try
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}catch(e)
{
try
{
xmlDoc=document.implementation.createDocument("","",null);
}catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load("TestData.xml");
}catch(e) {alert(e.message)}
document.write("TestData without List<HR><table border='1'>");
var x=xmlDoc.getElementsByTagName("TestData");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x.getElementsByTagName("Name")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("Value")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table><HR>");
}
I am very new to TestComplete + javascript and began with developing a function which would help to retrieve the xml node value from test data of xml, but I am getting an error saying the "document" is undefined!!! But the same code is working well and fine in Browser!!!!! Someone please help me with this.. The sample code below for your review.
function getxml() {
try
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}catch(e)
{
try
{
xmlDoc=document.implementation.createDocument("","",null);
}catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load("TestData.xml");
}catch(e) {alert(e.message)}
document.write("TestData without List<HR><table border='1'>");
var x=xmlDoc.getElementsByTagName("TestData");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x.getElementsByTagName("Name")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("Value")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table><HR>");
}