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 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Having some Trouble...

    ok, so here is the code im using:
    Code:
    function getmessage()
    {
    //Get list of definition tags
    var glossary = xmlDoc.getElementsByTagName('definition');
    //Elements plaecholder
    var elements = new Array();
    //document.write(glossary.length); //Test length of glossary in words
    
    //Using length of glossary, put information into elements placeholder
    	for (i=0;i<glossary.length;i++)
    	{
    		// Get words and put them into first element of array
    		var word_length = xmlDoc.getElementsByTagName("word");
    		var word = word_length[i].childNodes[0].nodeValue;
    		 	//document.write(word);
    		elements[i] = new Array(word);
    		//	document.write(elements[i][0]);
    
    		//Get sections and put them into the second element of array
    		var section_length = xmlDoc.getElementsByTagName("section");
    		var section = section_length[i].childNodes[0].nodeValue;
    		elements[i][1] = section;
    
    		//Get definitions and put them into third element of array
    		var def_length = xmlDoc.getElementsByTagName("def");
    		var def = def_length[i].childNodes[0].nodeValue;
    		elements[i][2] = def;
    
    		document.write(elements[i][0]);
    		document.write("<br>");
    		document.write(elements[i][1]);
    		document.write("<br>");
    		document.write(elements[i][2]);
    		document.write("<br>");
    	}
    
    // Rest of code is after this
    The problem I run into is this: It does exactly what I want it to do, stores the data to an array and prints it exactly how I want it, however it does not seem to either exit the for loop or something weird, as the rest of the script will not run, and in firefox it prints my dad then sits there saying "Loading..." with the circle spinning.

    When i comment out that entire for loop the rest of the script will run, so I have to assume it has something to do with that. Anyone have any suggestions?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Where is xmlDoc defined? What is it?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    xmlDoc info:
    Code:
    <script type="text/javascript">
    var xmlDoc;
    function loadXML()
    {
    // code for IE
    if (window.ActiveXObject)
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false;
      xmlDoc.load("glossary.xml");
      getmessage();
      }
    // code for Mozilla & other browsers
    else{
      xmlDoc=document.implementation.createDocument("","",null);
      xmlDoc.load("glossary.xml");
      xmlDoc.onload=getmessage;
      }
    }

  • #4
    New Coder
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone have any ideas?

  • #5
    New Coder
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am still stuck here. If anyone has any ideas or suggestions for me to try that would be very helpful. Here is my full code:

    Code:
    <script type="text/javascript">
    var xmlDoc;
    //Elements plaecholder
    var elements = new Array();
    function loadXML()
    {
    // code for IE
    if (window.ActiveXObject)
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false;
      xmlDoc.load("glossary.xml");
      getmessage();
      }
    // code for Mozilla & other browsers
    else{
      xmlDoc=document.implementation.createDocument("","",null);
      xmlDoc.load("glossary.xml");
      xmlDoc.onload=getmessage;
      }
    }
    
    function getmessage()
    {
    //Get list of definition tags
    var glossary = xmlDoc.getElementsByTagName('definition');
    //document.write(glossary.length); //Test length of glossary in words
    
    //Using length of glossary, put information into elements placeholder
    	for (i=0;i<glossary.length;i++)
    	{
    		// Get words and put them into first element of array
    		var word_length = xmlDoc.getElementsByTagName("word");
    		var word = word_length[i].childNodes[0].nodeValue;
    		 	//document.write(word);
    		elements[i] = new Array(word);
    		//	document.write(elements[i][0]);
    
    		//Get sections and put them into the second element of array
    		var section_length = xmlDoc.getElementsByTagName("section");
    		var section = section_length[i].childNodes[0].nodeValue;
    		elements[i][1] = section;
    
    		//Get definitions and put them into third element of array
    		var def_length = xmlDoc.getElementsByTagName("def");
    		var def = def_length[i].childNodes[0].nodeValue;
    		elements[i][2] = def;
    
    		document.write(elements[i][0]);
    		document.write("<br>");
    		document.write(elements[i][1]);
    		document.write("<br>");
    		document.write(elements[i][2]);
    		document.write("<br>");
    	}
    
    /////////////////////////////////////////////////////////////////////////
    
    	var words = new Array();
    	var word_count = 0;
    
    	var arrElements = document.getElementsByTagName('span');
    	for (i=0;i<arrElements.length;i++)
    	{
    		if(arrElements[i].className == "word")
    		{
    			words[word_count] = arrElements[i].firstChild.nodeValue;
    			//alert(words[word_count]);
    			word_count++;
    		}
    	}
    
    }
      </script>
    Last edited by mynameisdave145; 10-24-2006 at 06:45 PM.


  •  

    Posting Permissions

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