Criando XML -->Dificuldade com TAG

Delphi

22/07/2013

Pessoal boa tarde, estou criando um XML para a NFE, estou usando o seguinte código:

with XMLDoc_ do begin
Root.addChild('NFe','http://www.portalfiscal.inf.br/nfe');
with Root.AddChild('infNFe') do begin
Root.Attributes['Id'] := 'NFe' ;
Root.Attributes['versao'] := '2.00';
end;
end;

que cria o seguinte cabeçalho de arquivo:

<?xml version="1.0" encoding="utf-8"?>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe" Id="NFe" versao="2.00">
<infNFe>


Preciso que seja assim especialmente a linha da versão:

<?xml version="1.0" encoding="utf-8"?>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="2.00" Id="">

Alguém tem uma dica?
Alexandre Estanieski

Alexandre Estanieski

Curtidas 0

Respostas

Rodolpho Silva

Rodolpho Silva

22/07/2013

Tente assim:
var
 infNode: IXMLNode;

with XMLDoc_ do 
begin
  Root.addChild('NFe','http://www.portalfiscal.inf.br/nfe');
  infNode := Root.AddChild('infNFe');
  infNode.Attributes['Id'] := 'NFe' ;
  infNode.Attributes['versao'] := '2.00';
end;


Uma dica? Evite usar o "with" aninhado. Isso confunde a leitura do código quando é muito grande.
GOSTEI 0
POSTAR