Recover XML Txmldocument at runtime (Delphi XE3)

Asked

Viewed 1,370 times

1

I am trying to recover the XML data but I can’t , Txmldocument is being created dynamically and is probably missing some configuration, because when I am using it visually in the project I can extract the data.

function TNFSe.getNumeroRPS(aCodCid, aCpfCnpjPrestador, aInscPrestador, aSerie:           string):   Integer;
    var EnviarRPS : LoteRps;
    sXML      : WideString;
    XMLDoc    : TXMLDocument;
    HTTR      : THTTPRIO;
    ANode     : IXMLNode;
   sNroUltimoRps,sArqEnvio,sRetorno : string ;
begin
try
  HTTR               := THTTPRIO.Create(nil);
  HTTR.URL           := URL;
  EnviarRPS          := HTTR as LoteRps;
  //busca o xml de envio
  sXML :=         '<?xml version="1.0" encoding="UTF-8"?>  ';
  sXML := sXML  + '<ns1:ConsultaSeqRps    xsi:schemaLocation="http://localhost:8080/WsNFe2/lote   http://localhost:8080/WsNFe2/xsd/ConsultaSeqRps.xsd" ';
  sXML := sXML  + 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:tipos="http://localhost:8080/WsNFe2/tp" xmlns:ns1="http://localhost:8080/WsNFe2/lote">';
  sXML := sXML  + '<Cabecalho> ';
  sXML := sXML  + '<CodCid>'+ aCodCid +'</CodCid> ';
  sXML := sXML  + '<IMPrestador>'+aInscPrestador +'</IMPrestador> ';
  sXML := sXML  + '<CPFCNPJRemetente>'+aCpfCnpjPrestador+'</CPFCNPJRemetente> ';
  sXML := sXML  + '<SeriePrestacao>'+aSerie+'</SeriePrestacao> ';
  sXML := sXML  + '<Versao>1</Versao> ';
  sXML := sXML  + '</Cabecalho> ';
  sXML := sXML  + '</ns1:ConsultaSeqRps> ';

  //xml de envio
  FXMLEnvio  := sXML;

  //recupera o xml de retorno
  FXMLRetorno := EnviarRPS.consultarSequencialRps(sXML);

  XMLDoc             := TXMLDocument.Create(nil);
  XMLDoc.LoadFromXML(FXMLRetorno) ;
  XMLDoc.Active:=True;

  //aqui varias tentativas de pegar os valores constante dentro do XML de retorno
  sNroUltimoRps :=   XMLDoc.DocumentElement.ChildNodes.First.ChildNodes.FindNode('NroUltimoRps').Text ;
  sNroUltimoRps := XMLDoc.DocumentElement.ChildNodes.FindNode('NroUltimoRps').Text;
  sNroUltimoRps := XMLDoc.DocumentElement.ChildNodes['NroUltimoRps'].text;

  //carrega as propriedades de retorno nas variaveis  
  FNroUltimoRps := StrToInt(sNroUltimoRps);
  FNroProximoRps := FNroUltimoRps + 1 ;
finally
  FreeAndNil(HTTR);
  FreeAndNil(XMLDoc);
end;
end;

1 answer

0


In the Create method parameter of Txmldocument you can’t pass Nil, must pass some object Tcomponent. You can use the Application , thus:

Xmldoc := Txmldocument.Create(Application);

  • Perfect Thank You Very Much... Thanks

  • You’re welcome... we’re there ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.