如何在Laravel 5.7中使用getElementByTagName在xml中获取值

时间:2019-03-26 04:38:40

标签: php xml laravel laravel-5

我想从xml获取错误值。我正在使用Laravel 5.7来做到这一点。我已经尝试过了,但是我没有得到想要的东西。

这是我的xml错误消息:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
  <SOAP-ENV:Fault>
     <faultcode>SOAP-ENV:Client</faultcode>
     <faultstring>Client Error</faultstring>
     <detail>
        <ResponseStatus>F</ResponseStatus>
        <ResponseCode>000</ResponseCode>
        <ResponseText>Error while executing the request:
    ApplicationError: (Server Message)
Category: 9
Number: 261
Call Sequence: 
Program Name: 
Text: Characteristic Type MCMX Characteristic Value BRACET combination, not found
Description: To solve the problem, check if the fields are populated, or the combination of them is a valid one to find an item in a table.
        </ResponseText>
     </detail>
  </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我想获取标记名称<ResponseText> => Text中的值错误。我已经尝试过,就像下面的代码一样:

$res = $response->getBody()->getContents();
$doc = new \DOMDocument();
$doc->loadXML($res);
$status = $doc->getElementsByTagName('ResponseText');
print_r($status);

我得到了这样的print_r结果:

DOMNodeList Object
(
    [length] => 0
)

如何解决我的问题?

0 个答案:

没有答案