Nextag API - SimpleXML won't work
I'm trying to pull in data from Nextag using their relatively simple api.
You can see a开发者_Go百科n example XML response by visiting:
http://api.nextag.com/buyer/synd.jsp?token=AgAg-V6vGl$rkqkUtxvd&ver=15&search=LG%2047LE8500
But I can't get Simple XML to work right with this data. I either get a constructor error or an empty object.
Here's what I have so far:
$xml = file_get_contents('http://api.nextag.com/buyer/synd.jsp?token=AgAg-V6vGl$rkqkUtxvd&ver=15&search=LG%2047LE8500');
$simple_xml = new SimpleXMLElement($xml);
And $simple_xml is always an empty object.
Is there something wrong with the response data? Am I doing something wrong? Is Simple XML just incompatible and if so, what should I do instead?
Thanks for the help!
UPDATE: Sean's answer was useful in that it helped get past the error, but the data is not being loaded, only the partial structure.
Looks like you need to tell it the namespace you want to parse. This seems to work:
$simple_xml = new SimpleXMLElement($xml, null, false, 'nxtg', true);
精彩评论