如何在 PHP 中解析复杂的 XML-RPC 结构?
这是我的 XML 对象: http://pastebin.com/0L8vf0ja 它是从以下位置创建的:
<?xml version="1.0" encoding="utf-8"?>
<methodResponse><params><param><value><struct><member><name>result</name><value><struct><member><name>application_instance_id</name><value><i4>89</i4></value></member></struct></value></member><member><name>status</name><value><i4>0</i4></value></member></struct></value></param></params></methodResponse>
我知道到这个级别:
$ApplicationInstanceID = (int)(string)$data->params->param->value->struct->member->
但是从这里开始,正如您在pastebin中看到的那样,它变成了一个对象数组 - 我不知道如何继续。
有什么想法吗?
Here is my XML object: http://pastebin.com/0L8vf0ja
Which was created from:
<?xml version="1.0" encoding="utf-8"?>
<methodResponse><params><param><value><struct><member><name>result</name><value><struct><member><name>application_instance_id</name><value><i4>89</i4></value></member></struct></value></member><member><name>status</name><value><i4>0</i4></value></member></struct></value></param></params></methodResponse>
I know upto this level:
$ApplicationInstanceID = (int)(string)$data->params->param->value->struct->member->
But from here, as you see in the pastebin, it becomes an array of objects - and I am not sure how to proceed.
Any ideas, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通过将其作为数组访问:
但是,如果启用了它,则
xmlrpc_decode
函数也许更容易使用。By accessing it as an array:
But, if you have it enabled, the
xmlrpc_decode
function is perhaps easier to use.我有点困惑 - 看起来您已经将 XML 解析为 PHP 对象...所以现在只需访问数组的子成员,就像访问数组的任何元素一样:
并且,对于它的属性:
I'm a bit confused -- it looks like you've already parses the XML into a PHP object... So now just access submembers of the array as you would any elements of an array:
And, for it's properties:
您可以尝试使用 xpath 来获取我认为的节点值,SimpleXml 实现了它...
http://php.net/manual/en/simplexmlelement.xpath.php
you could try to use xpath to get the node value i think, SimpleXml implements it...
http://php.net/manual/en/simplexmlelement.xpath.php