Web Analytics Made Easy -
StatCounter XML Glossary Database - Help - CodingForum


No announcement yet.

XML Glossary Database - Help

  • Filter
  • Time
  • Show
Clear All
new posts

  • XML Glossary Database - Help

    OK this is what I want to do. I am making a website for a class, which has a list of defined words for a glossary. I have chosen to use XML to store these items. There is a few things I want to do with this which I am having trouble with:
    1. I have a tooltip script that allows users to hover over words to see the definition - what I want to do is to somehow have this automated when a specific word is say wrapped in a certain tag. (I.E. a span or the like)

    Here is a the sample XML doc I have been working with:
    <?xml version="1.0"?>
    	<definition id="1">
    		<def>Music is great</def>
    	<definition id="2">
    		<def>Song is great</def>
    So Far:
    I have successfully loaded the xml data into an array (elements) using the following script, yet it does not seem to want to exit my for loop and continue the rest of the script for one reason or another. I have tried making the for loop "i=0;i<glossary.length-1;i++" wit no avail, all that does is cut out the last word in the array. Why would this not be continuing the rest of the script?
    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;
    Also, from here, how would I go about searching this array on command and displaying the definition (elements[x][2]) within the tooltip as I want to do? Any suggestions or help would be great.

  • #2
    Try giving you variable another name than "glossary", let's say "myGlossary", as you have a tag glossary as well.

    id must not start with a digit. The first character of an id must be a letter or un underscore only.

    And do not use document.write() method. It is not a dynamic method. Use DOM methods to create and append elements. Or, at least use innerHTML method. It is not a standard method but it is a crossbrowser dynamic method as well.

    I would have used the more precise documentElement root

    var myGlossay =xmlDoc.documentElement.getElementsByTagName('definition')
    Offshore programming