I have this XML and I'm using SimpleXMLElment with xpath method to select first eSocial
node:
<?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>
The search works when I use absolute xpath /soap:Envelope/soap:Body
but when trying relative (//eSocial)[1]
xpath I got no results. Code:
(new SimpleXMLElement($xml))->xpath('/soap:Envelope/soap:Body');
// SimpleXMLElement {#192}
(new SimpleXMLElement($xml))->xpath('(//eSocial)[1]');
// []
Which xpath should I use to get first occurrence of eSocial
tag?