Parse a XML element with AJAX

Discussion in 'JavaScript' started by XandroZ, Jul 18, 2007.

  1. #1
    I need to parse a element from a XML file:

    <a>
    <b>45</b>
    <c>67</c>
    </a>

    <a>
    <b>98</b>
    <c>89</c>
    </a>

    So I try to read and put in a html element the first value of b with the next code:


    
    document.getElementById("apDiv3").innerHTML=xmlDoc.getElementsByTagName("b")[0].data;
    
    or
    
    document.getElementById("apDiv3").innerHTML=xmlDoc.getElementsByTagName("b")[0].value;
    
    
    Code (markup):
    and I get a undefined message.Where is the problem?
     
    XandroZ, Jul 18, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Try with this:
    
    document.getElementById("apDiv3").innerHTML = xmlDoc.getElementsByTagName("b")[0].firstChild.nodeValue;
    
    Code (markup):
     
    ajsa52, Jul 18, 2007 IP
  3. XandroZ

    XandroZ Peon

    Messages:
    395
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes it works,thanks, but now I have another problem : I have a radiogroup and I want to change a variable in function of what radio button of the radiogroup is selected
     
    XandroZ, Jul 19, 2007 IP