Fórum ler tag no delphi com TXMLDocument #576755
10/03/2017
0
<tpAmb>1</tpAmb>
<verAplic>1.1.1</verAplic>
<cStat>138</cStat>
<xMotivo>Documento localizado para o destinatario</xMotivo>
<dhResp>2017-03-06T17:54:28</dhResp>
<indCont>1</indCont>
<ultNSU>20531283364</ultNSU>
<ret>
<resNFe NSU="20531085938">
<chNFe>41170204634168000967550010001178731909897608</chNFe>
<CNPJ>04634168000967</CNPJ>
<xNome>DPS DISTRIBUIDORA DE PECAS SANTOS LTDA</xNome>
<IE>9060797126</IE>
<dEmi>2017-02-20</dEmi>
<tpNF>1</tpNF>
<vNF>1113.48</vNF>
<digVal>ferL25tdxQOhu+6cioBj+fguIS8=</digVal>
<dhRecbto>2017-02-20T18:01:38</dhRecbto>
<cSitNFe>1</cSitNFe>
<cSitConf>4</cSitConf>
</resNFe>
</ret>
</retConsNFeDest>
O código que eu uso é o seguinte...
var
vXMLDoc: TXMLDocument;
begin
vXMLDoc := TXMLDocument.Create(self);
Try
// abre o XML
vXMLDoc.LoadFromFile('D:\\'+data+'.xml');
// Le os dados contido nó principal
with vXMLDoc.DocumentElement do
begin
ultNSU := ChildNodes['ultNSU'].Text;
end;
Memo4.Clear;
Memo4.Lines.Add(ultNSU);
finally
VXMLDoc.Free;
end;
end;
Desde já obrigado pela atenção.
Marcos Cunha
Curtir tópico
+ 0Post mais votado
14/03/2017
procedure TForm1.Button1Click(Sender: TObject);
var
_node1, _node2, _node3, _node4: IXMLNode;
begin
Memo1.Lines.Clear;
XMLDocument1.LoadFromFile('nota.xml');
_node1 := XMLDocument1.ChildNodes.FindNode('retConsNFeDest');
if _node1 <> nil then
begin
Memo1.Lines.Add('-retConsNFeDest');
_node2 := _node1.ChildNodes.FindNode('ret');
if _node2 <> nil then
begin
Memo1.Lines.Add('--ret');
_node3 := _node2.ChildNodes.FindNode('resNFe');
if _node3 <> nil then
begin
Memo1.Lines.Add('---resNFe');
_node4 := _node3.ChildNodes.FindNode('chNFe');
if _node4 <> nil then
begin
Memo1.Lines.Add('----chNFe');
Memo1.Lines.Add(_node4.NodeValue);
end;
end;
end;
end;
end;Raylan Zibel
Gostei + 1
Mais Posts
10/03/2017
Raimundo Pereira
Fiz algo interessante, uma busca de qualquer TAG do XML, veja se ajuda...
1. Declere as três funções.
private
{ Private declarations }
Function Subistituir_String(Conteudo,Conteudo_Procurado,Novo_Conteudo:string):string;
Function Load_XML(Caminho_XML:string):Boolean;
Function Localizar_String(Conteudo_Procurado:string):String;
implementation
{$R *.dfm}
Function TFP.Localizar_String(Conteudo_Procurado:string):String;
var
IProcura : Integer;
begin
Pasta.ItemIndex:=0;
iProcura:=Pasta.Perform(LB_SELECTSTRING, 0, LongInt(PChar('<'+Conteudo_Procurado+'>')));
if iProcura >= 0 then
begin
Pasta.ItemIndex:=iProcura;
Result:=(Pasta.Items.Strings[iprocura]);
Result:=Subistituir_String(Result,'<'+Campo_para_leitura_XML+'>','');
Result:=Subistituir_String(Result,'</'+Campo_para_leitura_XML+'>','');
end;
end;
Function TFP.Load_XML(Caminho_XML:string):Boolean;
begin
Pasta:=TListBox.Create(self);
Pasta.Parent:=FP;
Pasta.Items.Clear;
Pasta.Align:=alBottom;
if not FileExists(Caminho_XML) then
begin
ShowMessage('Arquivo XML, não localizado em ['+Caminho_XML+']');
end
else
begin
Pasta.Items.LoadFromFile(Caminho_XML);
if Pasta.Items.Count=0 then
begin
ShowMessage('Nenhum registro encontrado');
end
else
begin
Result:=true;
end;
end;
end;
Function TFP.Subistituir_String(Conteudo,Conteudo_Procurado,Novo_Conteudo:string):string;
begin
Result:=StringReplace(Conteudo, Conteudo_Procurado, Novo_Conteudo,
[rfReplaceAll, rfIgnoreCase]);
end;
Realizando sua consulta
procedure TFP.BTN_CarregarClick(Sender: TObject);
begin
if Load_XML('c:\\aplic\\Arquivo de Retorno.xml') = true then
begin
Campo_para_leitura_XML := 'chNFe'; // Campo que eu quero pesquisar
ShowMessage(Localizar_String(Campo_para_leitura_XML));
end;
end;
Gostei + 0
10/03/2017
Raimundo Pereira
Em Uses : Vcl.StdCtrls ou Vcl.StdCtrls
var
Pasta: TListBox;
Campo_para_leitura_XML: string;
Gostei + 0
10/03/2017
Raimundo Pereira
Depois de Pasta:=TListBox.Create(self);
Faça isso
Pasta.visible:=false;
Gostei + 0
13/03/2017
Marcos Cunha
Tá osso... kkkk
obrigado pela atenção.
Gostei + 0
13/03/2017
Jean Teixeira
Logo aós isso faça o seguinte código :
function CarregarcteProc(const FileName: string): IXMLCteProcType;
begin
Result := LoadXMLDocument(FileName).GetDocBinding('cteProc', TXMLCteProcType, TargetNamespace) as IXMLCteProcType;
end;
A partir disso você tem um objeto do tipo IXMLCteProcType. Dessa forma voce pode pegar ou alterar qualquer valor a partir da interface.
Gostei + 0
14/03/2017
Raylan Zibel
Gostei + 0
14/03/2017
Marcos Cunha
Apesar do meu pouco conhecimento sigo a disposição para qualquer coisa que possa ajudar.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)