无法将Fogbugz API响应转换为SimpleXML对象 [英] Having trouble getting Fogbugz API response into a SimpleXML object

查看:90
本文介绍了无法将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.

这篇关于无法将Fogbugz API响应转换为SimpleXML对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆