Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    XML and Java String Will Not Display

    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.
    Code:
    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"

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,460
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Can you post firstxml.xml for us?

    I see a few obvious boo-boos, though:

    Code:
    	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".
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the suggestion, I have fixed all the little obvious boo-boos and I will try your option. Here is the xml
    Code:
    <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!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •