C
catronro
I want to read an xml file and build a string based on that file. But
when i try to implement it i get an Object Required error. Any help
would be greatly appreciated.
try
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var html = "";
xmlDoc.load('siteMap.xml');
var xmlObj=xmlDoc.documentElement;
alert(xmlObj.xml);
for(var i=0; i < xmlObj.childNodes.length; i++)
{
var path = xmlObj.childNodes(i).getAttribute("address");
var name = xmlObj.childNodes(i).firstChild.text;
html += "<a href='" +path+ "'>"+name+"</a>
";
}
document.write(html);
}
catch(err)
{
alert(err.description);
}
This is the file im trying to read in
<?xml version="1.0" encoding="utf-8" ?>
<mainSiteMap>
<siteMap address="home.htm">HOME</siteMap>
<siteMap address="events.htm">EVENTS</siteMap>
<siteMap address="contacts.htm">CONTACTS</siteMap>
<siteMap address="albums.htm">ALBUMS</siteMap>
<siteMap address="register.htm">REGISTER</siteMap>
</mainSiteMap>
This is how i call the javascript in my HTML file
<script type="text/javascript" src="Code/Javascript.js"></script>
when i try to implement it i get an Object Required error. Any help
would be greatly appreciated.
try
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var html = "";
xmlDoc.load('siteMap.xml');
var xmlObj=xmlDoc.documentElement;
alert(xmlObj.xml);
for(var i=0; i < xmlObj.childNodes.length; i++)
{
var path = xmlObj.childNodes(i).getAttribute("address");
var name = xmlObj.childNodes(i).firstChild.text;
html += "<a href='" +path+ "'>"+name+"</a>
";
}
document.write(html);
}
catch(err)
{
alert(err.description);
}
This is the file im trying to read in
<?xml version="1.0" encoding="utf-8" ?>
<mainSiteMap>
<siteMap address="home.htm">HOME</siteMap>
<siteMap address="events.htm">EVENTS</siteMap>
<siteMap address="contacts.htm">CONTACTS</siteMap>
<siteMap address="albums.htm">ALBUMS</siteMap>
<siteMap address="register.htm">REGISTER</siteMap>
</mainSiteMap>
This is how i call the javascript in my HTML file
<script type="text/javascript" src="Code/Javascript.js"></script>