...

View Full Version : XML and Java String Will Not Display



Theopile
06-17-2009, 09:12 AM
Hello, i have created an xml document to house menu links and text and a javascript file to construct the menu structure to be written into the page which will then be rendered by the css on the html page. Z will not display anything and I am at wits end looking at syntax and flipping things around.
Any help is greatly appreciated.

var xmlDoc;
if (window.XMLHttpRequest)
{
xmlDoc=new window.XMLHttpRequest();
xmlDoc.open("GET","firstxml.xml",false);
xmlDoc.send("");
xmlDoc=xmlDoc.responseXML;
}
// IE 5 and IE 6
else if (ActiveXObject("Microsoft.XMLDOM"))
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("firstxml.xml");
}
function display()
{
var x=xmlDoc.getElementsByTagName("CELL");
var y=xmlDoc.getElementsByTagName("HREF");
var z="";
z='<ul><li><a href="'
z+=y[0].getElementsByTagName("HREF")[0].childNodes[0].nodeValue;
z+='" class="hide">'
z+=x[0].getElementsByTagName("CELL")[0].childNodes[0].nodeValue;
z+='</a><ul>';
for (i=1;i<x.length;i++)
{if(x.tagname="MINISTRY")
{z+='<li><a href"';
z+=y[i].getElementsByTagName("HREF")[0].childNodes[0].nodeValue;
z+='">';
z+=x[i].getElementsByTagName("CELL")[0].childNodes[0].nodeValue;
z+='</a></li>';
}
if(x.tagname="DISTRO")
{z+='</ul></li><li><a href="';
z+=y[i].getElementsByTagName("HREF")[0].childNodes[0].nodeValue;
z+='" class="hide">';
z+=x[i].getElementsByTagName("CELL")[0].childNodes[0].nodeValue;
z+='</a><ul>';
}
if(x.tagname="MINISTRYHUB")
{z+='<li><a href"';
z+=y[i].getElementsByTagName("HREF")[0].childNodes[0].nodeValue;
z+='">';
z+=x[i].getElementsByTagName("CELL")[0].childNodes[0].nodeValue;
z+='</a><ul>';
}
if(x.tagname="MINISTRYSUB")
{z+='<li><a href"';
z+=y[i].getElementsByTagName("HREF")[0].childNodes[0].nodeValue;
z+='">';
z+=x[i].getElementsByTagName("CELL")[0].childNodes[0].nodeValue;
z+='</a></li>';
}
if(x.tagname="MINISTRYSUBPOS")
{z+='</ul></li><li><a href"';
z+=y[i].getElementsByTagName("HREF")[0].childNodes[0].nodeValue;
z+='">';
z+=x[i].getElementsByTagName("CELL")[0].childNodes[0].nodeValue;
z+='</a></li>';
}
z+='</ul></li></ul>'

document.getElementById("menu").innerHTML=z;
}
"ignore the for loops range i know its wrong ill just put in an iteger"

Alex Vincent
06-18-2009, 01:31 AM
Can you post firstxml.xml for us?

I see a few obvious boo-boos, though:


for (i=1;i<x.length;i++)
{if(x.tagname="MINISTRY")


If x is a node list, then it won't have an element name - try x[i].localName.toUpperCase() == "MINISTRY".

Theopile
06-18-2009, 05:26 AM
Thanks for the suggestion, I have fixed all the little obvious boo-boos and I will try your option. Here is the xml

<MINISTRY>
<CELL>
<DISTRO>Main</DISTRO>
<MINISTRY>Hospitality</MINISTRY>
<MINISTRY>Nurses</MINISTRY>
<MINISTRYHUB>Music Deparment</MINISTRYHUB>
<MINISTRYSUB>Music Ministry</MINISTRYSUB>
<MINISTRYSUB>Choir Director</MINISTRYSUB>
<MINISTRYSUB>Praise Team</MINISTRYSUB>
<MINISTRYSUBPOS>Birthday Ministry</MINISTRYSUBPOS>
<MINISTRY>Armor Bearer Ministry</MINISTRY>
</CELL>
<HREF>
<LINK>#</LINK>
<LINK>#</LINK>
<LINK>#</LINK>
<LINK>#</LINK>
</HREF>
</MINISTRY>
I want to loop through the children of Cell, check their names and then add appropriate html tags to form a menu. Thanks for the help!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum