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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    <ITEM id="206"> Read-out ID-value

    Hi,

    Retrieving a xml-file and reading the nodeValues of the different Childs is working fine.

    For future possibilities I added an id to every item.

    My question is: how can I read-out the id-value of every item using the routine mentioned below?

    Thanks for Your effort,
    Jerome

    XML-file:

    <?xml version="1.0"?>
    <PRODUCTS>
    <ITEM id="206">
    <MODEL>extra large</MODEL>
    <YEAR>1990</YEAR>
    </ITEM>
    <ITEM id="207">
    <MODEL>large</MODEL>
    <YEAR>1991</YEAR>
    </ITEM>
    <ITEM id="208">
    <MODEL>medium</MODEL>
    <YEAR>1991</YEAR>
    </ITEM>
    <ITEM id="209">
    <MODEL>small</MODEL>
    <YEAR>2000</YEAR>
    </ITEM>
    </PRODUCTS>

    Routine:

    var cont=xmlDoc.documentElement.childNodes;

    data="";
    data+="<table>";
    for(i=0;i<=cont.length-1;i++)
    {
    data+="<tr><td>ID-VALUE</td><td>"+cont[i].childNodes[k].text+"</td></tr>";
    }
    data+="</table>";

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,453
    Thanks
    1
    Thanked 21 Times in 19 Posts
    Document Object Model, Level One:

    "<tr><td>" + cont[i].childNodes[k].getAttribute("id") + "</td>..."

    http://www.w3.org/tr/domhttp://www.w...el-1-19981001/
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for Your effort Alex!

    Ofcourse, it works fine

    Jerome


  •  

    Posting Permissions

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