我有这个XML,我使用SimpleXMLElment和xpath方法来选择第一个eSocial
节点:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header></soap:Header>
<soap:Body>
<eSocial xmlns="http://www.esocial.gov.br/schema/lote/eventos/envio/retornoEnvio/v2_2_02">
...
</eSocial>
</soap:Body>
</soap:Envelope>
当我使用绝对xpath /soap:Envelope/soap:Body
时,搜索有效,但在尝试相对(//eSocial)[1]
xpath时,我没有得到任何结果。代码:
(new SimpleXMLElement($xml))->xpath('/soap:Envelope/soap:Body');
// SimpleXMLElement {#192}
(new SimpleXMLElement($xml))->xpath('(//eSocial)[1]');
// []
我应该使用哪个xpath来首次出现eSocial
代码?