DELPHI - LER XML

13/01/2021

0

Boa tarde!

Estou tentando ler o seguinte XML:

<eSocial xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.esocial.gov.br/schema/download/retornoProcessamento/v1_0_0">
<retornoProcessamentoDownload>
<evento>
<eSocial xmlns="http://www.esocial.gov.br/schema/evt/evtTabEstab/v02_05_00">
<evtTabEstab Id="ID1323007800000002019050916050853323">
<ideEvento>
<tpAmb>1</tpAmb>
<procEmi>1</procEmi>
<verProc>5.07 E S-1005</verProc>
</ideEvento>
<ideEmpregador>
<tpInsc>1</tpInsc>
<nrInsc>000000</nrInsc>
</ideEmpregador>
<infoEstab>
<inclusao>
<ideEstab>
<tpInsc>1</tpInsc>
<nrInsc>00000000000</nrInsc>
<iniValid>2019-01</iniValid>
</ideEstab>
<dadosEstab>
<cnaePrep>000000</cnaePrep>
<aliqGilrat>
<aliqRat>2</aliqRat>
<fap>1.0000</fap>
<aliqRatAjust>2.0000</aliqRatAjust>
</aliqGilrat>
<infoTrab>
<regPt>1</regPt>
<infoApr>
<contApr>0</contApr>
</infoApr>
<infoPCD>
<contPCD>0</contPCD>
</infoPCD>
</infoTrab>
</dadosEstab>
</inclusao>
</infoEstab>
</evtTabEstab>

Para teste, estou fazendo da seguinte forma:

XMLDocument1.LoadFromFile('C:\naovai.xml');

Memo1.Lines.Add(XMLDocument1.ChildNodes.FindNode('eSocial').
ChildNodes.FindNode('retornoProcessamentoDownload').
ChildNodes.FindNode('evento').
ChildNodes.FindNode('eSocial').
ChildNodes.FindNode('evtTabEstab').
ChildNodes.FindNode('ideEmpregador').
ChildValues['nrInsc']);

Porém sempre ocorre o erro "access violation" e observei que é devido aos itens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" e xmlns="http://www.esocial.gov.br/schema/download/retornoProcessamento/v1_0_0"> da primeira tag.

Como eu poderia conseguir ler ela normalmente?

Obrigado desde já!
Nomad

Nomad

Responder

Post mais votado

15/01/2021

tente assim:
var
  no_Evento: IXMLNode;
  no_ideEmpregador: IXMLNode;
  str_ChildnrInsc: string;
  str_ChildtpInsc: string;
begin
  XMLDocument1.Active := False;
  XMLDocument1.LoadFromFile('d:\\temp\\teste2.xml');
  XMLDocument1.Active := True;

  no_Evento := XMLDocument1.ChildNodes.FindNode('eSocial').
                 ChildNodes.FindNode('retornoProcessamentoDownload').
                 ChildNodes.FindNode('evento');

  // o segredo está em *FindNode('eSocial','')*, onde é passado um segundo parâmetro vazio
  no_ideEmpregador := no_Evento.ChildNodes.FindNode('eSocial','').
    ChildNodes.FindNode('evtTabEstab').
    ChildNodes.FindNode('ideEmpregador');

  str_ChildnrInsc := no_ideEmpregador.ChildValues['nrInsc'];
  str_ChildtpInsc := no_ideEmpregador.ChildValues['tpInsc'];

  Memo1.Clear;
  Memo1.Lines.Add('Tipo inscrição: ' + str_ChildtpInsc);
  Memo1.Lines.Add('Número inscrição: ' + str_ChildnrInsc);
end;

Emerson Nascimento

Emerson Nascimento
Responder

Mais Posts

13/01/2021

Emerson Nascimento

no lugar de
XMLDocument1.ChildNodes
tente
XMLDocument1.DocumentElement.ChildNodes
Responder

13/01/2021

Nomad

Fiz um teste aqui e ocorreu o mesmo erro.
Responder

14/01/2021

Nomad

UP!
Responder

14/01/2021

Emerson Nascimento


esse xml está completo ?
não consigo abri-lo nem no navegador.

estão faltando tags ou fechamento de tags.

Responder

14/01/2021

Nomad

Realmente, não está completo. Tinha colocado somente a parte que identifiquei que influenciou para ocorrer o erro. Segue todo o XML:


<?xml version="1.0"?>
-<eSocial xmlns="http://www.esocial.gov.br/schema/download/retornoProcessamento/v1_0_0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-<retornoProcessamentoDownload>
-<evento>
-<eSocial xmlns="http://www.esocial.gov.br/schema/evt/evtTabEstab/v02_05_00">
-<evtTabEstab Id="ID1323007800000002019050916050853323">
-<ideEvento>
<tpAmb>1</tpAmb>
<procEmi>1</procEmi>
<verProc>5.07 E S-1005</verProc>
</ideEvento>
-<ideEmpregador>
<tpInsc>1</tpInsc>
<nrInsc>000000</nrInsc>
</ideEmpregador>
-<infoEstab>
-<inclusao>
-<ideEstab>
<tpInsc>1</tpInsc>
<nrInsc>00000000000000</nrInsc>
<iniValid>2019-01</iniValid>
</ideEstab>
-<dadosEstab>
<cnaePrep>4721102</cnaePrep>
-<aliqGilrat>
<aliqRat>2</aliqRat>
<fap>1.0000</fap>
<aliqRatAjust>2.0000</aliqRatAjust>
</aliqGilrat>
-<infoTrab>
<regPt>1</regPt>
-<infoApr>
<contApr>0</contApr>
</infoApr>
-<infoPCD>
<contPCD>0</contPCD>
</infoPCD>
</infoTrab>
</dadosEstab>
</inclusao>
</infoEstab>
</evtTabEstab>
-<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
-<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
-<Reference URI="">
-<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>f8GuIi2hgzLwDe7/kiwdLLXwZa4mgx8JKAyb30aWoxA=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>hRImK5ZbXWelQFr/tLEd5khuRkwEVeFcEXUG07H6HDFmQYsm3LfgGp3Z/z1pvwsOO+IGEDaMhpdbt0bng5omVGcGWtfBZQjuQ57EkuQEEVokglXwrQjrfP0DLfVNLFsTXx3Rlydau92ZhYiQ5UUhjr980hj3JeAZ/OP7f7t1/muaqGNg/sYCk71LRnEg88KGz+aV+TTvbt1hyBEmAlvMv0WJu+W3epmhfJ/n18J+4dtrwTxkG0GM64fw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A3YzA5BggrBgEFBQcwAYYtaHR0cDovL29jc3AtYWMtY2VydGlzaWduLXJmYi5jZXJ0aXNpZ24uY29tLmJyMA0GCSqGSIb3DQEBCwUAA4ICAQA6Nh6ByRKlA4wKOUfv4QP8SPOoUeKHTs6DD3C2i47dCIy0rSHirOhTTVq6sLy1f3DuOQm1iWuudZhHPVtBLOEZezGq/hu9pZDxWnDJ6zBX5wOWZdKy+yvHnYANqnlFCIlcuMZHBqD+cpaijKwUD+jofMNsXOnpvIJ7E3X/6/cV4iTZltV022l1huBtJfNt+LZzxhixeDmMo5+vQdMOvX0VWJlDW/BgX2z21093Tlyq1YQ4jbjjaX1419LR9JaPA7DlKGVuxkCBWb6KBQ7RKNQmJmlYMu8pu80vuvM0mZtJOatw4QoeUBfeTUyZ0ncNj8xW8wPAuPfKXNOZrix2B65crgnRn6//8ITXnHBxrBxYqVE19DHfIQIJM2AdSZkr/iiuJznL1WJvePv+W2CsKXmyHiN3LVOo07KgHfFo+I+uTjhxtzOZYTIEqIM+JIcXqeZC0/cGbDgHgJQkO8WU1rO4t2TzyezU8pNtGZHJkeD3RMceLbXubTENy5EgtZwAYl0GsJOwufO/Ga5a0TVMWanWdQTxoWtOsV+Te/i7z8VnG/CITk/uJ83CeSZpYS7SY4+j2O+6wNY1Af77K6CZKnKVlHPdP4fxerbsgagS9hjfo1Q0GFiT9HQ/eEZOopwZrjBvJGxInaYiQtMgvCmaViOPpNV6kYcVzt2hgSzwQ+eRyA==</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</eSocial>
</evento>
-<recibo>
-<eSocial xmlns="http://www.esocial.gov.br/schema/evt/retornoEvento/v1_2_1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-<retornoEvento Id="ID1323007800000002019050916050853323">
-<ideEmpregador>
<tpInsc>1</tpInsc>
<nrInsc>000000</nrInsc>
</ideEmpregador>
-<recepcao>
<tpAmb>1</tpAmb>
<dhRecepcao>2019-05-09T16:05:07.203</dhRecepcao>
<versaoAppRecepcao>0.1.0-A0352</versaoAppRecepcao>
<protocoloEnvioLote>1.1.201905.0000000000503852267</protocoloEnvioLote>
</recepcao>
-<processamento>
<cdResposta>201</cdResposta>
<descResposta>Sucesso.</descResposta>
<versaoAppProcessamento>12.0.0-A4229</versaoAppProcessamento>
<dhProcessamento>2019-05-09T16:05:07.27</dhProcessamento>
</processamento>
-<recibo>
<nrRecibo>1.1.0000000004488205765</nrRecibo>
<hash>f8GuIi2hgzLwDe7/kiwdLLXwZa4mgx8JKAyb30aWoxA=</hash>
</recibo>
</retornoEvento>
-<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
-<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
-<Reference URI="">
-<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>PIghHiabpPYyAr2ITfJthOP2pe47weNuCH5uV4yufxE=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>3HsKvoF1FruCB80BiYxpQhEM0xIS1ZvnP3KL59VMKLJ6kn9EQj9zB28N0+WmyfY6dCHJMa+nmtOUC4LDU4sbb3upGQMRYo8wtfNL9FhjDYW9RTIDO/Q7q21c0VLrsrC/73RL+y8YuVILXf/Aaneo5fyNZr9k9EYg44NZ1A+6prBiGGe/gvTqBOm68p3oedb6cyNEQEjieeoYYWU7hJHJ8m77KZXWUtkz8o8xrLDztyLh6n4YknQUaLLj5rR/nYgqY9bfhLfeCaE3M5BWheIcQIDWfHyVCcyP1ewNABEDA9SlLz7HVvO52tE11emqz0r1acGdTdFbNt5SNQdp5gJMaQ==</SignatureValue>
-<KeyInfo>
-<X509Data>
<X509Certificate>MIIITzCCBjegAwIBAgIDAvCEMA0GCSqGSIb3DQEBCwUAMIGOMQswCQYDVQQGEwJCUjETMBEGA1UECgwKSUNQLUJyYXNpbDE2MDQGA1UECwwtU2VjcmV0YXJpYSBkYSBSZWNlaXRhIEZlZGVyYWwgZG8gQnJhc2lsIC0gUkZCMTIwMAYDVQQDDClBdXRvcmlkYWRlIENlcnRpZmljYWRvcmEgZG8gU0VSUFJPUkZCIFNTTDAeFw0xODA5MTMxNTA3MTJaFw0xOTA5MTMxNTA3MTJaMIGmMQswCQYDVQQGEwJCUjETMBEGA1UECgwKSUNQLUJyYXNpbDE2MDQGA1UECwwtU2VjcmV0YXJpYSBkYSBSZWNlaXRhIEZlZGVyYWwgZG8gQnJhc2lsI
Responder

14/01/2021

Nomad

UP!
Responder

15/01/2021

Nomad

Cara, deu tudo certo aqui.... mais uma vez me salvando!!!

Muito obrigado mesmo pela sua ajuda, mais uma vez hahaha! Vlww
Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar