I need to parse a element from a XML file:



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




and I get a undefined message.Where is the problem?

Your XML file is not proper, there can be only one root element. Also since you have not posted the entire code, I would give you a small example on how to go about things:

// Javascript file

    <title>XML DOM</title>
    <script type="text/javascript">
    var xmlDoc;
    function parse()
        alert('in parse');
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = false;
        else if(document.implementation.createDocument)
            xmlDoc = document.implementation.createDocument("", "", null);
            xmlDoc.onload = display;
            alert("Browser doesn't support XML DOM manipulation");
        alert('out parse');
    function display()
        alert('In display');
        document.getElementById('b1').innerHTML = xmlDoc.getElementsByTagName("b")[0].childNodes[0].nodeValue;
        document.getElementById('c1').innerHTML = xmlDoc.getElementsByTagName("c")[0].childNodes[0].nodeValue;
        document.getElementById('b2').innerHTML = xmlDoc.getElementsByTagName("b")[1].childNodes[0].nodeValue;
        document.getElementById('c2').innerHTML = xmlDoc.getElementsByTagName("c")[1].childNodes[0].nodeValue;
<body onload="parse();">
    <p>b1: <span id="b1"></span></p>
    <p>c1: <span id="c1"></span></p>
    <p>b2: <span id="b2"></span></p>
    <p>c2: <span id="c2"></span></p>
// XML Document


In case of any queries, do ask again.

thanks you , your example help me.
Yes I know about only one root element.The xml code it was just a example inside the root elemet to understand what I want.

I am back with an other question.

I want to put the xml elements values using a for cycle in input fields


I want that input_element to be a variable that depend on i, and in function of i to represent a real html input element value.
Can you give me a solution?