无法获取 SimpleXMLElement 内容
Can't get SimpleXMLElement content
抱歉,我找不到任何解决我问题的方法。
我正在使用 PHP 并且我有以下 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>
<nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeInutilizacao4">
<retInutNFe versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe">
<infInut>
<tpAmb>2</tpAmb>
<verAplic>AJXNZiasn</verAplic>
<cStat>102</cStat>
<xMotivo>Inutilizacao de numero homologado</xMotivo>
<cUF>20</cUF>
<ano>20</ano>
<CNPJ>169</CNPJ>
<mod>65</mod>
<serie>123</serie>
<nNFIni>140</nNFIni>
<nNFFin>140</nNFFin>
<dhRecbto>2020-04-20T15:27:49-03:00</dhRecbto>
<nProt>9019848505847</nProt>
</infInut>
</retInutNFe>
</nfeResultMsg>
</soap:Body>
</soap:Envelope>
我使用 SimpleXMLElement
如下:
function xmlAdapter(string $xml) {
$xmlElement = new \SimpleXMLElement($xml);
$document = [
'xmlElement' => $xmlElement,
'xml' => $xml
];
return $document; }
但是document->xmlElement
returns{}
.
我想要的是抓取 nfeResultMsg
标签内的所有内容,但我找不到访问它的方法。我想用 nfeResultMsg
.
中的内容保存一个新的 xml 文档
有人知道我怎么能做这样的事情吗?非常感谢。
抛开功能和其他一切,为了"to grab everything that is inside nfeResultMsg tag"你可以使用
$xml->xpath('//*[local-name()="nfeResultMsg"]');
抱歉,我找不到任何解决我问题的方法。
我正在使用 PHP 并且我有以下 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>
<nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeInutilizacao4">
<retInutNFe versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe">
<infInut>
<tpAmb>2</tpAmb>
<verAplic>AJXNZiasn</verAplic>
<cStat>102</cStat>
<xMotivo>Inutilizacao de numero homologado</xMotivo>
<cUF>20</cUF>
<ano>20</ano>
<CNPJ>169</CNPJ>
<mod>65</mod>
<serie>123</serie>
<nNFIni>140</nNFIni>
<nNFFin>140</nNFFin>
<dhRecbto>2020-04-20T15:27:49-03:00</dhRecbto>
<nProt>9019848505847</nProt>
</infInut>
</retInutNFe>
</nfeResultMsg>
</soap:Body>
</soap:Envelope>
我使用 SimpleXMLElement
如下:
function xmlAdapter(string $xml) {
$xmlElement = new \SimpleXMLElement($xml);
$document = [
'xmlElement' => $xmlElement,
'xml' => $xml
];
return $document; }
但是document->xmlElement
returns{}
.
我想要的是抓取 nfeResultMsg
标签内的所有内容,但我找不到访问它的方法。我想用 nfeResultMsg
.
有人知道我怎么能做这样的事情吗?非常感谢。
抛开功能和其他一切,为了"to grab everything that is inside nfeResultMsg tag"你可以使用
$xml->xpath('//*[local-name()="nfeResultMsg"]');