我正在运行PHP 7.0.0Beta3(我现在正在编译RC1。我有一个问题。
<?php
$XML = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetExampleResponse xmlns="http://example.net/webservices">
<GetExampleResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="CENTER" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<CENTER>POLICE PSAP</CENTER>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<CENTER>POLICE PSAP</CENTER>
</Table>
</NewDataSet>
</diffgr:diffgram>
</GetExampleResult>
</GetExampleResponse>
</soap:Body>
</soap:Envelope>
XML;
$XML = new SimpleXMLElement(str_ireplace(['soap:', 'xs:', 'xmlns:', 'msdata:', 'diffgr:'], '', $XML));
print_r($XML->Body->GetExampleResponse->GetExampleResult->diffgram->NewDataSet);
print_r($XML->Body->GetExampleResponse->GetExampleResult->diffgram->NewDataSet->Table);
?>
该脚本的输出是
SimpleXMLElement Object
(
[Table] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => Table1
[rowOrder] => 0
)
[CENTER] => POLICE PSAP
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => Table2
[rowOrder] => 1
)
[CENTER] => POLICE PSAP
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => Table1
[rowOrder] => 0
)
[CENTER] => POLICE PSAP
)
两个print_r行之间的唯一区别是我要再向下一级->Table
,但是这样做,我不再得到阵列,我只能得到它的第一个元件。
这是print_r($XML->Body->GetExampleResponse->GetExampleResult->diffgram->NewDataSet->Table);
来电的预期结果。
Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => Table1
[rowOrder] => 0
)
[CENTER] => POLICE PSAP
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => Table2
[rowOrder] => 1
)
[CENTER] => POLICE PSAP
)
)
这是一个错误,还是我做错了什么?