El parser php es el siguiente:
Código PHP:
<?php
$file = "xxx.xml";
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
function startElement2($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ALBUM":
$main = "ITEMS";
break;
case "TOPALBUMS":
$main = "TOPALBUMS";
break;
default:
$currently_writing = $name;
break;
}
}
function endElement2($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ALBUM") {
$item_counter++;
}
}
function characterData2($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
if ($currently_writing != "") {
switch($main) {
case "IMAGE":
if (isset($rss_channel[$main][$currently_writing])) {
$rss_channel[$main][$currently_writing] .= $data;
} else {
$rss_channel[$main][$currently_writing] = $data;
}
break;
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement2", "endElement2");
xml_set_character_data_handler($xml_parser, "characterData2");
if (!($fp = fopen($file, "r"))) {
die("No Results");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
// output as HTML
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
if ($i < '10') {
print ("\n
<div>" . $rss_channel["ITEMS"][$i]["NAME"] . "</div>
");
}
}
} else {
print ("<b>No data found.</b>");
}
}
?>
Código:
Puedo mostrar sin ningun problema con el parser los campos <name> o <url> pero no logro mostrar el campo <large> de <image><topalbums artist="xxx"> <album> <name>album name</name> <url>http://www.page.com</url> <image> <large> http://wwww.page.com/imagen.jpg </large> </image> </album> </topalbums>
alguna ayuda por favor?
Un saludo