Having trouble getting Fogbugz API response into a SimpleXML object

天大地大妈咪最大 提交于 2019-12-12 02:29:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!