Boa tarde,
Fui gerar o XML e notei que o ocorreu o erro novamente, mesmo com a alteração. Então, após uma nova análise, descobri que no momento de buscar o conteúdo dentro da tag <protNFeZip> e descompactar, ele acaba recebendo o valor "<?xml version="1.0" encoding="utf-8"?>" antes da tag <protNFe>. Em Anexo os 2 XML's, com o código original e o código alterado.
Abaixo o código onde a operação é realizada.
Antes:
// XML do Protocolo da NF-e
StrStream := TStringStream.Create('');
try
try
StrAux := RetornarConteudoEntre(Leitor.Grupo, '<protNFeZip>', '</protNFeZip');
StrDecod := DecodeBase64(StrAux);
StrStream.WriteString(StrDecod);
FretNFe.Items[i].FProtNFeZip := UnZipMsg(StrStream);
except
on e : Exception do
begin
Raise Exception.Create(e.message);
end;
end;
finally
FreeAndNil(StrStream);
end;
Depois (Apenas um modo de solucionar o problema. Talvez vocês saibam uma maneira melhor de fazer isso):
// XML do Protocolo da NF-e
StrStream := TStringStream.Create('');
try
try
StrAux := RetornarConteudoEntre(Leitor.Grupo, '<protNFeZip>', '</protNFeZip');
StrDecod := DecodeBase64(StrAux);
StrStream.WriteString(StrDecod);
FretNFe.Items[i].FProtNFeZip := UnZipMsg(StrStream);
FretNFe.Items[i].FProtNFeZip := '<protNFe' + RetornarConteudoEntre(FretNFe.Items[i].FProtNFeZip, '<protNFe', '</protNFe>') + '</protNFe>';
except
on e : Exception do
begin
Raise Exception.Create(e.message);
end;
end;
finally
FreeAndNil(StrStream);
end;
Antes_43150502656032000175550010000011931000011934-nfe.xml
Depois_43150502656032000175550010000011931000011934-nfe.xml
Antes_43150502656032000175550010000011931000011934-nfe.xml
Depois_43150502656032000175550010000011931000011934-nfe.xml