gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 20:27:00 26 4
gpt4 key购买 nike

我有这样的回复:

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

关于cakephp - 将xml对象(带属性)内的xml解析为cakephp中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17214140/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com