hello,
I have a javascript that pulls links for a site im building from an xml file... im am running into a problem when i try to pull the subLink elements... if they are empty the for loop stops and doesn't out put the rest of the links.. I have tried an if statement with a continue then I tried a break.. neither seemed to work. here are the too files:
and the java:PHP Code:<mainNavigation>
<link>
<name>Home</name>
<url>http://www.hydrocephalus-network.org</url>
<subName />
<subUrl />
</link>
<link>
<name>News</name>
<url>http://www.hydrocephalus-network.org/news/</url>
<subName>RSS Feed</subName>
<subUrl>http://www.hydrocephalus-network.org/news/feed.php</subUrl>
</link>
<link>
<name>Hydrocephalus Information</name>
<url>http://www.hydrocephalus-network.org/info.php</url>
<subName>test</subName>
<subUrl />
</link>
<link>
<name>Professional Community</name>
<url>http://www.hydrocephalus-network.org/proCommunity.php</url>
<subName />
<subUrl />
</link>
<link>
<name>Your Story</name>
<url>http://www.hydrocephalus-network.org/stories.php</url>
<subName />
<subUrl />
</link>
<link>
<name>Network Events</name>
<url>http://www.hydrocephalus-network.org/events.php</url>
<subName />
<subUrl />
</link>
<link>
<name>Message Board</name>
<url>http://www.hydrocephalus-network.org</url>
<subName />
<subUrl />
</link>
<link>
<name>Contact Us</name>
<url>http://www.hydrocephalus-network.org/contact.php</url>
</link>
</mainNavigation>
an example of the out put i am trying to get is as follows:PHP Code:var xmlDoc;
if (window.ActiveXObject) {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("xmlData/mainLinks.xml");
//main categoies
var x = xmlDoc.getElementsByTagName('name');
var y = xmlDoc.getElementsByTagName('url');
var links = xmlDoc.getElementsByTagName('link');
//sub links
var subName = xmlDoc.getElementsByTagName('subName');
var subUrl = xmlDoc.getElementsByTagName('subUrl');
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument) {
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.async=false;
xmlDoc.load("xmlData/mainLinks.xml");
} else {
alert('Your browser cannot view the News Section. Please upgrade to the latest Internet Explorer or Mozilla FireFox');
}
//main links
var x = xmlDoc.getElementsByTagName('name');
var y = xmlDoc.getElementsByTagName('url');
var links = xmlDoc.getElementsByTagName('link');
//sub links
var subName = xmlDoc.getElementsByTagName('subName');
var subUrl = xmlDoc.getElementsByTagName('subUrl');
for (var i=0;i<links.length;i++) {
document.write('- <b><a href="');
document.write(y[i].childNodes[0].nodeValue);
document.write('" class="navLink">');
document.write(x[i].childNodes[0].nodeValue);
document.write('</a></b><br />');
}
- News
RSS Feed
News is the main link and RSS Feed is the sub link indented... if anyone can help i would appreciate it.. thanks


Reply With Quote
Bookmarks