问题
I'm trying to write a wrapper around the fogbugz API, starting with getting a login token. I don's seem to be able to get the token into my wrapper object.
$url = "http://..../fogbugz/api.asp?cmd=logon&email=" . $_UN . "&password=" . $_PW;
$contents = file_get_contents($url);
$resp = simplexml_load_file($contents);
print_r($resp);
Response is: SimpleXMLElement Object ( [token] => SimpleXMLElement Object ( ) ) The object in the token member var is empty. The response string however is OK. If I use
header("Content-type: text/xml");
echo $contents;
I get the correct XML back from the API. Furthermore, if I use the xml as a string, directly in the code it works fine:
$xml = "<?xml version='1.0'?><response><token>iibgo9d785iavs5av5a6lrimbn2r54</token></response>";
$resp = simplexml_load_string($xml);
print_r ($resp);
Response: SimpleXMLElement Object ( [token] => iibgo9d785iavs5av5a6lrimbn2r54 ) Can anyone please tell me how to get the response token into the SimpleXML Object?
回答1:
I think the XML returned from the API might look like this actually:
<?xml version='1.0'?><response><token><![CDATA[iibgo9d785iavs5av5a6lrimbn2r54]]><token><response>
SimpleXML can't parse CDATA objects.
来源:https://stackoverflow.com/questions/9870598/having-trouble-getting-fogbugz-api-response-into-a-simplexml-object