I'm trying to parse data from Archive.org's search functionality. The data looks like this:
<doc>
<float name="avg_rating">5.0</float>
<arr name="collection"><str>U-Melt</str><str>etree</str></arr>
<arr name="format"><str>Checksums</str><str>Flac</str><str>Flac FingerPrint</str>
<str>Metadata</str><str>Ogg Vorbis</str><str>Text</str><str>VBR M3U</str>
<str>VBR MP3</str><str>VBR ZIP</str></arr>
<str name="identifier">umelt2009-09-19.main.km184.flac16</str>
<str name="mediatype">etree</str>
<int name="num_reviews">1</int>
</doc>
Here's a link to the full XML.
PHP's SimpleXML picks up fine getting to each doc, and can read the items labeled str and arr just fine. It's the items labeled float, int or long that it freaks out on, and I can't figure out why.
My parsing code is as follows:
/* OPENING FILE */
$xml = simplexml_load_file($pathname.$identifier_list);
//Check the file to make sure it's got XML in it
$xmlCheck = file_get_contents($pathname.$identifier_list);
$xmlCheck = substr($xmlCheck,0,4);
if (!$xmlCheck == "<?xm") {
die("<p>WARNING: ".$filename." doesn't looks like XML, quitting. Check it to see what's wrong.");
}
else {
$result = $xml->result;
echo "<br/><br/>".$result['name']."<br/>";
$counter = 1;
foreach ($result->doc as $doc) {
echo "<br/><b>Document ".$counter."</b>";
$counter++;
foreach ($doc->children() as $item) {
echo $item->getName();
switch ((string) $item['name']) {
case 'identifier':
echo "<br/>Identifier: ".$item."\n";
break;
case 'licenseurl':
echo "<br/>License URL: ".$item."\n";
break;
case 'mediatype':
echo "<br/>Mediatype: ".$item."\n";
break;
case 'downloads':
echo "<br/>Downloads: ".$item."\n";
break;
case 'avg_rating':
echo "<br/>Average Rating: ".$item."\n";
break;
case 'collection':
echo "<br/>Collection: ".$item."\n";
break;
}
}
echo "<br/>";
}
}
I've tried using ->children(), ->doc and ->long or ->int. None of these seem to pick up the long/int/float items. I'm beginning to think that it's because they're primitives, but I don't know how to fix this issue.
Thanks in advance for your help.