AJAX simple problem!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theS70RM
    New Member
    • Jul 2007
    • 107

    AJAX simple problem!

    hi, i think im missing something here....

    i have some xml stored in javascript:

    <picture>
    <date>5-5-2007</date>
    <title>Pictur e title</title>
    <filename>filen ame.jpg</filename>
    <size>6x4</size>
    </picture>

    i have stored "picture"

    Code:
    var XMLinfo = xmlDoc.getElementsByTagName('picture');
    all i then want to do, is list the childnode names and each of their values, this is what ive done so far:


    Code:
    var n = XMLinfo.childNodes.length;
    var output = "";
    
    	for (i=0;i<n;i++)
    	{			
    	   if (infoName != "#text" && infoName != "")
    	   {
    		output += XMLinfo.childNodes[i].nodeName;
    		output += ": ";
    
                     //this is the line with the problem
    		output += XMLinfo.childNodes.item(i).nodeValue;
    	   }
    
          }
         alert(output);

    It shows the node names but Ive tried all sorts of combinations of syntax for the second line but cant get it to show the value.

    Also tried:

    Code:
    infoName = XMLinfo.childNodes[i].nodeName;  XMLinfo.getElementsByTagName(infoName)[0].childNodes[0].nodeValue
    but that didnt work either. I know i could getElementByTag Name() for each child node, but some "picture" nodes have a different number of childnodes so wanted to do it automatically.

    Anybody see where i am going wrong?

    thanks!

    Andy
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Do either of these work?
    output += XMLinfo.childNo des[i].nodeValue;
    output += XMLinfo.childNo des[i].childeNodes[0].nodeValue;

    Comment

    • theS70RM
      New Member
      • Jul 2007
      • 107

      #3
      Originally posted by jkmyoung
      Do either of these work?
      output += XMLinfo.childNo des[i].nodeValue;
      output += XMLinfo.childNo des[i].childeNodes[0].nodeValue;


      nope afraid not:

      first one returns null
      second one gives and error and returns nothing

      i don't understand, i seem to have tried every combination!

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        output += XMLinfo.childNo des[i].childNodes[0].nodeValue;

        I spelled child wrong. Yeah, not sure why it's not working then, if you can get the name, but not the children nodes of it.

        Comment

        • theS70RM
          New Member
          • Jul 2007
          • 107

          #5
          Originally posted by jkmyoung
          output += XMLinfo.childNo des[i].childNodes[0].nodeValue;

          I spelled child wrong. Yeah, not sure why it's not working then, if you can get the name, but not the children nodes of it.

          yea clocked the spelling mistake cheers.

          what i dont understand is that when i use:

          XMLinfo.getElem entsByTagName(' title')[0].childNodes[0].nodeValue

          it returns the title no problem so i know the xml is ok. just cant see the other way of accessing this node other than using getElementsByTa gName()

          Comment

          Working...