XML Feed Question

webmasterbeta

New Member
I have an XML feed to display the 10 most popular ringtones. And this being my first time attempting this, I have used PHP and XML: Parsing RSS 1.0 (<!-- m --><a class="postlink" href="http://www.sitepoint.com/article/php-xml-parsing-rss-1-0">http://www.sitepoint.com/article/php-xm ... ng-rss-1-0</a><!-- m -->) tutorial to guide me along the way. I modified the script to fit my needs, and Im havng some problems.

Here is the XML link I am using:
<!-- m --><a class="postlink" href="http://www.cellus-usa.com/API/top10.php?usr=">http://www.cellus-usa.com/API/top10.php?usr=</a><!-- m --><usr>&pwd=<pwd>

Which displays the top 10 ringtones:

<Top10Ringtones>
<Ringtone>
<Rank>1</Rank>
<Code>0197</Code>
<Artist>LEANN+RIMES</Artist>
<Title>CAN%27T+FIGHT+THE+MOONLIGHT+%28VERSION+2%29</Title>
<Mono>1</Mono>
<Poly>0</Poly>
</Ringtone>

<Ringtone>
<Rank>2</Rank>
<Code>6968</Code>
<Artist>NELLY+FT.+TIM+MCGRAW</Artist>
<Title>OVER+AND+OVER</Title>
<Mono>1</Mono>
<Poly>1</Poly>
</Ringtone>

etc. etc. etc.


Here is the modified code I am using to display the ringtones rank, artist, title and auth code.

<?php

$insideitem = false;
$tag = "";
$rank = "";
$artist = "";
$title = "";
$code = "";

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $rank, $artist, $title;
if ($insideitem) {
$tag = $name;
} elseif ($name == "ITEM") {
$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $rank, $artist, $title, $code;
if ($name == "ITEM") {
printf("<dt><b><a href='http://www.webdeveloper.com/forum/archive/index.php/%s'>%s</a></b></dt>",
trim($title),htmlspecialchars(trim($rank)));
printf("<dd>%s</dd>",htmlspecialchars(trim($artist)));
$rank = "";
$artist = "";
$title = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $rank, $artist, $title, $code;
if ($insideitem) {
switch ($tag) {
case "RANK":
$rank .= $data;
break;
case "ARTIST":
$artist .= $data;
break;
case "TITLE":
$title .= $data;
break;
case "CODE":
$code .= $data;
break;

}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://www.cellus-usa.com/API/top10.php?usr=user&pwd=pass","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>


I am getting a blank page when I do my testing. Did I use the right tutorial, Is my link not an RSS link (<!-- m --><a class="postlink" href="http://www.cellus-usa.com/API/top10.php?usr=">http://www.cellus-usa.com/API/top10.php?usr=</a><!-- m --><usr>&pwd=<pwd>)?
 
Back
Top