Home > Backend Development > PHP Tutorial > 如何把返回的xml转成数组. 这个xml的结构第一次接触, google了一翻, 没有找到解决方法

如何把返回的xml转成数组. 这个xml的结构第一次接触, google了一翻, 没有找到解决方法

WBOY
Release: 2016-06-23 13:44:50
Original
855 people have browsed it

内容:

<?xml version='1.0' encoding='UTF-8'?><ns1:getActivityOptionsResponse xmlns:ns1="http://www.ebay.com/marketplace/returns/v1/services"><ns1:ack>Success</ns1:ack><ns1:version>1.1.0</ns1:version><ns1:timestamp>2014-11-21T07:05:54.874Z</ns1:timestamp><ns1:activityOptions>ISSUE_REFUND</ns1:activityOptions></ns1:getActivityOptionsResponse>
Copy after login



请指教,谢谢



回复讨论(解决方案)

你这是带命名空间的 XML,指定一下就可以了

$s =<<< XML<?xml version='1.0' encoding='UTF-8'?><ns1:getActivityOptionsResponse xmlns:ns1="http://www.ebay.com/marketplace/returns/v1/services"><ns1:ack>Success</ns1:ack><ns1:version>1.1.0</ns1:version><ns1:timestamp>2014-11-21T07:05:54.874Z</ns1:timestamp><ns1:activityOptions>ISSUE_REFUND</ns1:activityOptions></ns1:getActivityOptionsResponse>XML;print_r(simplexml_load_string($s, null, 0, 'ns1', true));
Copy after login
SimpleXMLElement Object(    [ack] => Success    [version] => 1.1.0    [timestamp] => 2014-11-21T07:05:54.874Z    [activityOptions] => ISSUE_REFUND)
Copy after login

谢谢你的帮助

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template