0
I’m trying to make an XML but the ns1 tag repeats in all xml ready, has to solve this in an easier way?
Example of the code:
function TRPS.geraXML:TStrings;
var XMLDoc : TXMLDocument;
ANode : IXMLNode;
begin
try
XMLDoc := TXMLDocument.Create(Application);
With XMLDoc do
begin
Active := True;
Version := '1.0';
Encoding := 'UTF-8';
AddChild('ns1:ReqEnvioLoteRPS');
DocumentElement.Attributes['xmlns:ns1'] := 'http://localhost:8080/WsNFe2/lote';
DocumentElement.Attributes['xmlns:tipos'] := 'http://localhost:8080/WsNFe2/tp';
DocumentElement.Attributes['xmlns:xsi'] := 'http://www.w3.org/2001/XMLSchema-instance';
DocumentElement.Attributes['xsi:schemaLocation'] := 'http://localhost:8080/WsNFe2/lote http://localhost:8080/WsNFe2/xsd/ReqEnvioLoteRPS.xsd';
ANode := DocumentElement;
with ANode.addChild('Cabecalho') do
begin
AddChild('CodCidade').NodeValue := Self.FPrestadorCidadeCodigoIBGE;
AddChild('CPFCNPJRemetente').NodeValue := Self.FPrestadorCPFCNPJ;
AddChild('RazaoSocialRemetente').NodeValue := Self.FPrestadorRazaoSocial;
AddChild('Transacao').NodeValue := Self.FRPSTransacao;
AddChild('DTInicio').NodeValue := FormatDateTime('yyyy-mm-dd',Self.FLoteDtInicio);
AddChild('DTFim').NodeValue := FormatDateTime('yyyy-mm-dd',Self.FLoteDTFim);
AddChild('QtdRPS').NodeValue := Self.FLoteQtdeRPS;
AddChild('ValorTotalServicos').NodeValue := VirgulaPorPonto(FormatFloat('#0.00',Self.FLoteValorTotalServicos));
AddChild('ValorTotalDeducoes').NodeValue := VirgulaPorPonto(FormatFloat('#0.00',Self.FLoteValorTotalDeducoes));
AddChild('Versao').NodeValue := Self.LoteVersao;
AddChild('MetodoEnvio').NodeValue := Self.FLoteMetodoEnvio;
end;
Result := XMLDoc.XML;
finally
FreeAndNil(XMLDoc);
end;
end;
example of XML delivered has the tag n1 everywhere
<?xml version="1.0"?>
-<ns1:ReqEnvioLoteRPS xsi:schemaLocation="http://localhost:8080/WsNFe2/lote http://localhost:8080/WsNFe2/xsd/ReqEnvioLoteRPS.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tipos="http://localhost:8080/WsNFe2/tp" xmlns:ns1="http://localhost:8080/WsNFe2/lote">
-<ns1:Cabecalho>
<ns1:CodCidade>0</ns1:CodCidade>
<ns1:CPFCNPJRemetente/>
<ns1:RazaoSocialRemetente/>
<ns1:Transacao/>
<ns1:DTInicio>1899-12-30</ns1:DTInicio>
<ns1:DTFim>1899-12-30</ns1:DTFim>
<ns1:QtdRPS>0</ns1:QtdRPS>
<ns1:ValorTotalServicos>0.00</ns1:ValorTotalServicos>
<ns1:ValorTotalDeducoes>0.00</ns1:ValorTotalDeducoes>
<ns1:Versao>0</ns1:Versao>
<ns1:MetodoEnvio/>
</ns1:Cabecalho>
</ns1:ReqEnvioLoteRPS>