加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

将xml对象(带属性)中的xml解析为cakephp中的数组

发布时间:2020-12-15 23:54:45 所属栏目:百科 来源:网络整理
导读:我有这样的回答: test xmlns="http://schemas.datacontract.org/2004/07/test.Messages.test" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" ProcessInstanceId xmlns="http://schemas.test.org/2004/07/test.Messages.Core"047d11f9-e381-4134-8bf
我有这样的回答:
<test xmlns="http://schemas.datacontract.org/2004/07/test.Messages.test" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <ProcessInstanceId xmlns="http://schemas.test.org/2004/07/test.Messages.Core">047d11f9-e381-4134-8bfa-da94cefda316</ProcessInstanceId>
    <ResultData i:type="a:InfoByZipCode" xmlns="http://schemas.test.org/2004/07/test.Messages.Core" xmlns:a="http://schemas.test.org/2004/07/test.DomainModel.Transient">
        <a:City>Bangalore</a:City>
        <a:County>India</a:County>
        <a:Products xmlns:b="http://schemas.test.org/2004/07/test.DomainModel.Views"/>
        <a:State>Connecticut</a:State>
        <a:StateCode>SBC</a:StateCode>
        <a:ZipCode>56001</a:ZipCode>
    </ResultData>
    <Success>TRUE</Success>
    <ResponseTime>2013-06-20T07:30:09.7558017-04:00</ResponseTime>
</test>

如何将其转换为数组格式?

据我所知,你想知道的一切都可以在Cakebook: http://book.cakephp.org/2.0/en/core-utility-libraries/xml.html中找到

因此,您可以将XML解析为数组,如下所示:

$xmlString = '<?xml version="1.0"?><root><child>value</child></root>'; // XML string
$xmlArray = Xml::toArray(Xml::build($xmlString));

结果你的$xmlArray会有这样的东西:

Array
(
    [root] => Array
       (
           [child] => value
       )
 )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读