无法将Fogbugz API响应转换为SimpleXML对象

问题描述:

我正在尝试围绕fogbugz API编写包装,从获取登录令牌开始.我似乎无法将令牌放入我的包装器对象中.

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); 

响应为:SimpleXMLElement对象([token] => SimpleXMLElement Object())令牌成员var中的对象为空.但是,响应字符串是可以的.如果我使用

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;

我从API返回了正确的XML.此外,如果我将xml用作字符串,则直接在代码中可以正常工作:

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);

响应:SimpleXMLElement对象([token] => iibgo9d785iavs5av5a6lrimbn2r54)谁能告诉我如何将响应令牌获取到SimpleXML对象中?

Response: SimpleXMLElement Object ( [token] => iibgo9d785iavs5av5a6lrimbn2r54 ) Can anyone please tell me how to get the response token into the SimpleXML Object?

我认为从API返回的XML实际上看起来像这样:

I think the XML returned from the API might look like this actually:

<?xml version ='1.0'?>>< response>< token><![CDATA [iibgo9d785iavs5av5a6lrimbn2r54]]>< token>< response>

<?xml version='1.0'?><response><token><![CDATA[iibgo9d785iavs5av5a6lrimbn2r54]]><token><response>

SimpleXML无法解析CDATA对象.

SimpleXML can't parse CDATA objects.