You are here:  » Cant parse this xml file


Cant parse this xml file

Submitted by womble on Fri, 2006-05-05 20:20 in

Having problems with this file http://www.pada.co.uk/cats.xml

Using the auto detect it fails and Ive tried

MagicParser_parse("$url","myRecordHandler","xml|GETCATEGORYLISTINGSRESPONSE/ITEMARRAY/");

But no luck. Im I missing somthing obvious?

Thanks

Submitted by womble on Sat, 2006-05-06 02:40

Dont worry fixed the bit above.

But can you spot why this does not work. Im not getting anything back.

<?php
  require("MagicParser.php");
  $url = "http://www.pada.co.uk/cats.xml";
  function myRecordHandler($item)
  {
  print "<B><a href='".$item["CATEGORYID"]."'>".$item["CATEGORYNAME"]."</a></B>";
  }
  MagicParser_parse("$url","myRecordHandler","xml|GETCATEGORYLISTINGSRESPONSE/CATEGORY/SUBCATEGORIES/CATEGORY/");
?>

Submitted by support on Sat, 2006-05-06 05:42

Hi,

It looks like the format string you're using isn't valid for that XML that is being returned currently. This is because SUBCATEGORIES is a child element of the top level; not CATEGORIES, so the correct format string I think should be:

xml|GETCATEGORYLISTINGSRESPONSE/SUBCATEGORIES/CATEGORY/

I just tried this new format string in your code, which then worked correctly:

<?php
  
require("MagicParser.php");
  
$url "http://www.pada.co.uk/cats.xml";
  function 
myRecordHandler($item)
  {
    print 
"<B><a href='".$item["CATEGORYID"]."'>".$item["CATEGORYNAME"]."</a></B>";
  }
  
MagicParser_parse("$url","myRecordHandler","xml|GETCATEGORYLISTINGSRESPONSE/SUBCATEGORIES/CATEGORY/");
?>

Cheers,
David.

Submitted by womble on Sat, 2006-05-06 06:16

Damn you've got good eyes. Thanks David. Would'nt believe how long ive been looking at that. I need a new pair of glasses :/