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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    problem displaying childnodes

    Hi guys,

    I'm new to this and I'm stuck with the following problem.
    I'm trying to generate a CD catalog from an XML file using JavaScript.
    I already managed to display the artist names and country, but can't find a way to display their albums, each seperated in another table-column.
    I'd prefer to keep the XML file unchanged.

    The result should look like this:

    Arcade Fire | Canada | Funeral | Neon Bible | The Suburbs

    Moby | United States | Play

    U2 | Ireland | War | October
    Thanks!

    JavaScript
    Code:
    var x=xmlDoc.getElementsByTagName("BAND");
    for (i=0;i<x.length;i++)
      { 
      document.write("<table border='1'><tr><td>");
      document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue);
      document.write("</td></tr></table><br />");
      }
    XML file
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!-- Edited by XMLSpy® -->
    <CATALOG>
    
    <BAND>
    <ARTIST>Arcade Fire</ARTIST>
    <COUNTRY>Canada</COUNTRY>
    <ALBUM>
       <TITLE>Funeral</TITLE>
    </ALBUM>
    <ALBUM>
       <TITLE>Neon Bible</TITLE>
    </ALBUM>
    <ALBUM>
       <TITLE>The Suburbs</TITLE>
    </ALBUM>
    </BAND>
    
    <BAND>
    <ARTIST>Moby</ARTIST>
    <COUNTRY>United States</COUNTRY>
    <ALBUM>
       <TITLE>Play</TITLE>
    </ALBUM>
    </BAND>
    
    <BAND>
    <ARTIST>U2</ARTIST>
    <COUNTRY>Ireland</COUNTRY>
    <ALBUM>
       <TITLE>War</TITLE>
    </ALBUM>
    <ALBUM>
       <TITLE>October</TITLE>
    </ALBUM>
    </BAND>
    
    </CATALOG>

  • #2
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks iBall, this is exactly what i needed!

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The list of bands is finished now thanks to iBall's solution.
    The idea is to turn all the band names into links, all directing to to the same .html file, but with the bandname added as extra information like this:

    Code:
    file:///F:/Music/Muziek/Website/test/albums.html?BandName=U2&
    The next step was turning this extra information into a variable called artist_var. This also works now, but I'm stuck at the last part.

    In this file albums.html, I only want to display all the albums with additional information from the band i selected in the previous page.
    I added some more elements, so now the XML-file looks like this:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!-- Edited by XMLSpy® -->
    <CATALOG>
    	<BAND>
    		<ARTIST>Arcade Fire</ARTIST>
    		<COUNTRY>Canada</COUNTRY>
    		<ALBUM>
    			<TITLE>Funeral</TITLE>
    			<TIME>40:33</TIME>
    			<GENRE>Indie Rock</GENRE>
    		</ALBUM>
    		<ALBUM>
    			<TITLE>Neon Bible</TITLE>
    			<TIME>41:58</TIME>
    			<GENRE>Indie Rock</GENRE>
    		</ALBUM>
    		<ALBUM>
    			<TITLE>The Suburbs</TITLE>
    			<TIME>34:41</TIME>
    			<GENRE>Indie Rock</GENRE>
    		</ALBUM>
    	</BAND>
    	
    	<BAND>
    		<ARTIST>Moby</ARTIST>
    		<COUNTRY>United States</COUNTRY>
    		<ALBUM>
    			<TITLE>Play</TITLE>
    			<TIME>51:47</TIME>
    			<GENRE>Electronic Rock</GENRE>
    		</ALBUM>
    	</BAND>
    
    	<BAND>
    		<ARTIST>U2</ARTIST>
    		<COUNTRY>Ireland</COUNTRY>
    		<ALBUM>
    			<TITLE>War</TITLE>
    			<TIME>56:41</TIME>
    			<GENRE></GENRE>
    		</ALBUM>
    		<ALBUM>
    			<TITLE>October</TITLE>
    			<TIME>1:05:44</TIME>
    			<GENRE>Rock</GENRE>
    		</ALBUM>
    	</BAND>
    
    </CATALOG>
    Can't seem to figure out how i can display only the BAND-element from the artist set in the variable artist_var. Suppose i selected U2, the albums.html file should look like:

    Code:
    U2 Ireland
    War 56:41 Rock
    October 1:05:44 Rock
    When this problem is solved, it's only a matter of adding extra information and markup and I'm finished.

  • #4
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Already found a solution. Thanks for the encouragement Lovely, sarcastic troll.


  •  

    Posting Permissions

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