Help me finish my code... im stuck

Discussion in 'XML' started by SM, Mar 14, 2007.

  1. SM

    SM Guest

    Hello,
    I have a xml file that contains the CD library of one artist. I want
    to extract all the tracks from a specific CD. I was able to extract
    the title of all the cd's but not the tracks of one specific CD.
    How can i extract track titles from a specific CD?

    Here's how my code looks like:
    var xmlResponse = xmlHttp.responseXML;

    xmlRoot = xmlResponse.documentElement;

    var arrayCD = xmlRoot.getElementsByTagName('title');

    for (var i=0; i<x.length; i++)
    {
    html += arrayCD.childNodes[0].nodeValue + '<br />';
    }

    //obtain a reference to the <div> element on the HTML page
    myDiv = document.getElementById("myDivElement");

    //display the HTML output
    myDiv.innerHTML = "Tracks: <br />" + html;

    I also notice that by specifying a number in the string
    'arrayCD[2].childNodes[0].nodeValue' i can access a specific cd.

    arrayCD[0].childNodes[0].nodeValue // to access cd 1
    arrayCD[1].childNodes[0].nodeValue // to access cd 2
    arrayCD[2].childNodes[0].nodeValue // to access cd 3

    I know im close, but im kinda lost.... that's why i need your help

    Here's how my xml file looks like:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <discography>
    <cd>
    <title>Hello</title>
    <track>
    <title>I want you</title>
    <title>Daydreamer</title>
    <title>Melody</title>
    </track>
    </cd>
    <cd>
    <title>White</title>
    </cd>
    <cd>
    <title>Can you</title>
    </cd>
    <cd>
    <title>Why</title>
    </cd>
    <cd>
    <title>Help</title>
    </cd>
    </discography>

    Thanks
    Marco
     
    SM, Mar 14, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Smedley
    Replies:
    1
    Views:
    296
    Steven Cheng[MSFT]
    Feb 14, 2004
  2. Miguel Dias Moura
    Replies:
    1
    Views:
    361
    Cor Ligthert
    Apr 12, 2004
  3. SZ
    Replies:
    11
    Views:
    571
    Richard Bos
    Nov 18, 2004
  4. focode
    Replies:
    1
    Views:
    1,843
    John B. Matthews
    Sep 8, 2009
  5. Charles Oliver Nutter

    Help finish the Nokogiri Java port

    Charles Oliver Nutter, Apr 11, 2010, in forum: Ruby
    Replies:
    0
    Views:
    100
    Charles Oliver Nutter
    Apr 11, 2010
Loading...

Share This Page