这是我从我正在使用的API
获得的XML响应resParam<?xml version="1.0"?>
<response>
<status>OK</status>
<order>
<id>137656566936059014</id>
<order_date>2013-08-15 12:21:09</order_date>
<price>50.00</price>
<payment>UNPAID</payment>
<payment_type>0</payment_type>
<order_type>delivery</order_type>
<status>2</status>
<details>sample</details>
<user>
<name>-</name>
<telephone></telephone>
<address_line_1>*ND*SC</address_line_1>
<address_line_2>-</address_line_2>
<postcode>*ND*FODSC</postcode>
<town></town>
<distance>*ND*POINTS</distance>
</user>
</order>
</response>
响应开始时有resParam
。我通过存储到像这样的变量
$string = '<?xml version="1.0"?> [ response xml content from API ] ';
$xml = simplexml_load_string($string ); //returns correct empty object
print_r( $xml );
它返回结果但不是第一个方法,其前面是字符串resParam
。我试过str_replace
然后它返回
< xsi:type="xsd:string"><?xml version="1.0"?>
<response>
<status>OK</status>
<order>
<id>137656566936059014</id>
<order_date>2013-08-15 12:21:09</order_date>
<price>50.00</price>
<payment>UNPAID</payment>
<payment_type>0</payment_type>
<order_type>delivery</order_type>
<status>2</status>
<details>sample</details>
<user>
<name>-</name>
<telephone></telephone>
<address_line_1>*ND*SC</address_line_1>
<address_line_2>-</address_line_2>
<postcode>*ND*FODSC</postcode>
<town></town>
<distance>*ND*POINTS</distance>
</user>
</order>
</response>
此结果中的额外< xsi:type="xsd:string">
是多少?
任何人都可以帮助我吗?或者我做错了什么?我该如何解析这个
修改
当我用萤火虫检查结果时,这就是我得到的
<env:envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:myOutputNamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"><env:body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"><ns1:getorderresponse env:encodingstyle="http://www.w3.org/2003/05/soap-encoding"><rpc:result></rpc:result><!--?xml version="1.0"?-->
<response>
<status>OK</status>
<order>
<id>137656566936059014</id>
<order_date>2013-08-15 12:21:09</order_date>
<price>50.00</price>
<payment>UNPAID</payment>
<payment_type>0</payment_type>
<order_type>delivery</order_type>
<status>2</status>
<details>sample</details>
<user>
<name>-</name>
<telephone></telephone>
<address_line_1>*ND*SC</address_line_1>
<address_line_2>-</address_line_2>
<postcode>*ND*FODSC</postcode>
<town></town>
<distance>*ND*POINTS</distance>
</user>
</order>
</response></ns1:getorderresponse></env:body></env:envelope>
我只需要响应标记内的数据。我怎样才能做到这一点?我认为这种尝试可以解决问题。