twilitegxa
03-26-2010, 05:09 PM
I am trying to write a script that displays all the CD's with a specific genre, but I am having some trouble. Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="cd_catalog.css"?>
<MUSIC>
<CD GENRE="Alternative">
<ALBUM>Plastic Beach</ALBUM>
<ARTIST>Gorillaz</ARTIST>
<SONG>White Flag</SONG>
<SONG>Rhinestone Eyes</SONG>
<SONG>Glitter Freeze</SONG>
<PRICE>$9.99</PRICE>
</CD>
<CD GENRE="Alternative">
<ALBUM>Save Me, San Francisco</ALBUM>
<ARTIST>Train</ARTIST>
<SONG>Parachute</SONG>
<SONG>Brick By Brick</SONG>
<SONG>This Aint Goodbye</SONG>
<PRICE>$11.99</PRICE>
</CD>
<CD GENRE="Heavy Metal">
<ALBUM>Paranoid</ALBUM>
<ARTIST>Black Sabbath</ARTIST>
<SONG>Iron Man</SONG>
<SONG>Hand Of Doom</SONG>
<SONG>Electric Funeral</SONG>
<PRICE>$9.89</PRICE>
</CD>
<CD GENRE="Heavy Metal">
<ALBUM>Mechanize</ALBUM>
<ARTIST>Fear Factory</ARTIST>
<SONG>Powershifter</SONG>
<SONG>Oxidizer</SONG>
<SONG>Controlled Demolition</SONG>
<PRICE>$13.99</PRICE>
</CD>
<CD GENRE="Rock/Pop">
<ALBUM>Smoke And Mirrors</ALBUM>
<ARTIST>Lifehouse</ARTIST>
<SONG>It Is What It Is</SONG>
<SONG>Here Today Gone Tomorrow</SONG>
<SONG>Nerve Damage</SONG>
<PRICE>$11.99</PRICE>
</CD>
<CD GENRE="Rock/Pop">
<ALBUM>Greatest Hits 1970-2002</ALBUM>
<ARTIST>Elton John</ARTIST>
<SONG>Candle In The Wind</SONG>
<SONG>Tiny Dancer</SONG>
<SONG>Your Song</SONG>
<PRICE>$15.99</PRICE>
</CD>
<CD GENRE="R/B">
<ALBUM>Thriller</ALBUM>
<ARTIST>Michael Jackson</ARTIST>
<SONG>Billie Jean</SONG>
<SONG>Someone In The Dark</SONG>
<SONG>The Girl IS Mine</SONG>
<PRICE>$6.99</PRICE>
</CD>
<CD GENRE="R/B">
<ALBUM>Stronger With Each Tear</ALBUM>
<ARTIST>Mary J. Blige</ARTIST>
<SONG>Tonight</SONG>
<SONG>Said And Done</SONG>
<SONG>The One</SONG>
<PRICE>$11.89</PRICE>
</CD>
<CD GENRE="Rap/Hip Hop">
<ALBUM>Element Of Freedom</ALBUM>
<ARTIST>Alicia Keys</ARTIST>
<SONG>Love Is Blind</SONG>
<SONG>Love Is My Disease</SONG>
<SONG>That's How Strong my Love Is</SONG>
<PRICE>$13.59</PRICE>
</CD>
<CD GENRE="Rap/Hip Hop">
<ALBUM>Battle Of The Sexes</ALBUM>
<ARTIST>Ludacris</ARTIST>
<SONG>How Low</SONG>
<SONG>Can't Live With You</SONG>
<SONG>Everybody Drunk</SONG>
<PRICE>$10.39</PRICE>
</CD>
</MUSIC>
And I was using this to display it, but it's not working for some reason. What have I done wrong?
<html>
<body>
<script type="text/javascript">
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}
xml=loadXMLDoc("KulaE_WDP3251_U1IP1.xml");
path="MUSIC/CD[@genre='Alternative']"
// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
for (i=0;i<nodes.length;i++)
{
document.write(nodes[i].childNodes[0].nodeValue);
document.write("<br />");
}
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();
while (result)
{
document.write(result.childNodes[0].nodeValue);
document.write("<br />");
result=nodes.iterateNext();
}
}
</script>
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="cd_catalog.css"?>
<MUSIC>
<CD GENRE="Alternative">
<ALBUM>Plastic Beach</ALBUM>
<ARTIST>Gorillaz</ARTIST>
<SONG>White Flag</SONG>
<SONG>Rhinestone Eyes</SONG>
<SONG>Glitter Freeze</SONG>
<PRICE>$9.99</PRICE>
</CD>
<CD GENRE="Alternative">
<ALBUM>Save Me, San Francisco</ALBUM>
<ARTIST>Train</ARTIST>
<SONG>Parachute</SONG>
<SONG>Brick By Brick</SONG>
<SONG>This Aint Goodbye</SONG>
<PRICE>$11.99</PRICE>
</CD>
<CD GENRE="Heavy Metal">
<ALBUM>Paranoid</ALBUM>
<ARTIST>Black Sabbath</ARTIST>
<SONG>Iron Man</SONG>
<SONG>Hand Of Doom</SONG>
<SONG>Electric Funeral</SONG>
<PRICE>$9.89</PRICE>
</CD>
<CD GENRE="Heavy Metal">
<ALBUM>Mechanize</ALBUM>
<ARTIST>Fear Factory</ARTIST>
<SONG>Powershifter</SONG>
<SONG>Oxidizer</SONG>
<SONG>Controlled Demolition</SONG>
<PRICE>$13.99</PRICE>
</CD>
<CD GENRE="Rock/Pop">
<ALBUM>Smoke And Mirrors</ALBUM>
<ARTIST>Lifehouse</ARTIST>
<SONG>It Is What It Is</SONG>
<SONG>Here Today Gone Tomorrow</SONG>
<SONG>Nerve Damage</SONG>
<PRICE>$11.99</PRICE>
</CD>
<CD GENRE="Rock/Pop">
<ALBUM>Greatest Hits 1970-2002</ALBUM>
<ARTIST>Elton John</ARTIST>
<SONG>Candle In The Wind</SONG>
<SONG>Tiny Dancer</SONG>
<SONG>Your Song</SONG>
<PRICE>$15.99</PRICE>
</CD>
<CD GENRE="R/B">
<ALBUM>Thriller</ALBUM>
<ARTIST>Michael Jackson</ARTIST>
<SONG>Billie Jean</SONG>
<SONG>Someone In The Dark</SONG>
<SONG>The Girl IS Mine</SONG>
<PRICE>$6.99</PRICE>
</CD>
<CD GENRE="R/B">
<ALBUM>Stronger With Each Tear</ALBUM>
<ARTIST>Mary J. Blige</ARTIST>
<SONG>Tonight</SONG>
<SONG>Said And Done</SONG>
<SONG>The One</SONG>
<PRICE>$11.89</PRICE>
</CD>
<CD GENRE="Rap/Hip Hop">
<ALBUM>Element Of Freedom</ALBUM>
<ARTIST>Alicia Keys</ARTIST>
<SONG>Love Is Blind</SONG>
<SONG>Love Is My Disease</SONG>
<SONG>That's How Strong my Love Is</SONG>
<PRICE>$13.59</PRICE>
</CD>
<CD GENRE="Rap/Hip Hop">
<ALBUM>Battle Of The Sexes</ALBUM>
<ARTIST>Ludacris</ARTIST>
<SONG>How Low</SONG>
<SONG>Can't Live With You</SONG>
<SONG>Everybody Drunk</SONG>
<PRICE>$10.39</PRICE>
</CD>
</MUSIC>
And I was using this to display it, but it's not working for some reason. What have I done wrong?
<html>
<body>
<script type="text/javascript">
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}
xml=loadXMLDoc("KulaE_WDP3251_U1IP1.xml");
path="MUSIC/CD[@genre='Alternative']"
// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
for (i=0;i<nodes.length;i++)
{
document.write(nodes[i].childNodes[0].nodeValue);
document.write("<br />");
}
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();
while (result)
{
document.write(result.childNodes[0].nodeValue);
document.write("<br />");
result=nodes.iterateNext();
}
}
</script>
</body>
</html>