SimpleXML不显示值

时间:2015-07-08 09:39:21

标签: php xml soap simplexml

我想知道为什么下面的代码在显示整个XML和Body标记时没有显示processResponse标记的值。

这是我正在处理的XML

$xml = '<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<env:Header>
<wsa:MessageID>urn:df1231asfer5e4564affds</wsa:MessageID>
<wsa:ReplyTo><wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address></wsa:ReplyTo>
</env:Header>
<env:Body>
<processResponse xmlns="http://xmlns.oracle.com/EligibilityProcess/EligibilityProcess/EligibilityBPEL">
   <generatedMessageRefNo>451</generatedMessageRefNo>
   <providerRefNo>41</providerRefNo>
   <tpaRequestId>4184612387</tpaRequestId>
   <contractHolder>Rami Zbeeb</contractHolder>
   <contractNo>81456954</contractNo>
   <guarantorName>ANC</guarantorName>
   <eligibilityStatus>Success</eligibilityStatus>
   <eligibilityReason xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
   <messageOrNotes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
   <patientShare></patientShare>
   <consentForm></consentForm>
   <webServTechStatus>Success</webServTechStatus>
   <replyCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
   <replyDescription xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</processResponse></env:Body></env:Envelope>';

我正在使用SimpleXML类:

$res = new SimpleXMLElement($xml);

当我显示正文XML时,它可以工作:

$str = $res->children('env',true)->Body->asXML();
echo "<pre>",htmlentities($str),"</pre>";

但是,当显示processResponse XML或字符串时,它不起作用:

$str = $res->children('env',true)->Body->processResponse->asXML();
echo "<pre>",htmlentities($str),"</pre>";

请提供建议。

1 个答案:

答案 0 :(得分:1)

您可以让Body的孩子获得processResponse

$str = $res->children('env',true)->Body->children()->processResponse->asXML();
echo "<pre>",htmlentities($str),"</pre>";