Retrieve XML TXMLDocument at runtime (Delphi XE3)

1

I'm trying to retrieve the XML data but I can not, the TXMLDocument is being created dynamically and probably is missing some configuration, because when I'm 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;
    
asked by anonymous 11.07.2014 / 16:51

1 answer

0

In the TXMLDocument Create method parameter you can not pass Nil , you must pass some TComponent object. You can use the Application , like this:

  

XMLDoc: = TXMLDocument.Create (Application);

    
13.07.2014 / 20:46