1

Criei um Documento XML, ao criar o 2o. Node 'Header' vem com o attribute do node anterior.

O Node é criado como <Header xmlns=""> como poderei remover o xmlns="" do Node

Usei o seguinte código

XML := NewXMLDocument;//initializate the interface
XML.Options := [doNodeAutoIndent];//activate the auto indentation
XML.Encoding:= 'Windows-1252';        //'ISO-8859-1';


XML := NewXMLDocument;
XML.Version := '1.0';
XML.Options := [doNodeAutoIndent,doAttrNull];
XML.Encoding := 'Windows-1252';
RootNode := XML.AddChild('AuditFile','');

RootNode.Attributes['xmlns:xsi'] := 'http://www.w3.org/2001/XMLSchema-instance';
RootNode.Attributes['xsi:schemaLocation'] := 'urn:OECD:StandardAuditFile-Tax:PT_1.04_01 .\SAFTPT1.04_01.xsd';
RootNode.Attributes['xmlns'] :='urn:OECD:StandardAuditFile-Tax:PT_1.04_01';

Node0 := RootNode.AddChild('Header');//add the task node
Node0.Resync;
  addChildToNode(Node0, 'Version','1.04_01', 10, True);
  addChildToNode(Node0, 'CompanyID'                ,'11111111111111', 50, True);
  addChildToNode(Node0, 'TaxRegistrationNumber'    ,'222222222222222222222',  9, True);
  addChildToNode(Node0, 'TaxAccountingBasis'       ,'F', 1, True );
  addChildToNode(Node0, 'CompanyName'              ,'444444444444444444444',100, True );  //Nome Registado
  addChildToNode(Node0, 'BusinessName'             ,'5555555555555555555555555555', 60, False );

O resultado foi:

<?xml version="1.0" encoding="Windows-1252"?>
<AuditFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:OECD:StandardAuditFile-Tax:PT_1.04_01 .\SAFTPT1.04_01.xsd" xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.04_01">
    `**`<Header xmlns="">`**
    `<Version>1.04_01</Version>
    <CompanyID>11111111111111</CompanyID>
    <TaxRegistrationNumber>222222222</TaxRegistrationNumber>
    <TaxAccountingBasis>F</TaxAccountingBasis>
    <CompanyName>444444444444444444444</CompanyName>
    <BusinessName>5555555555555555555555555555</BusinessName>
  </Header>
</AuditFile>

Como fazer para o <Header xmlns=""> passar a <Header>

1
  • Ja tentou o StringReplace(Texto_XML,'<Header xmlns="">', '<Header>', [rfReplaceAll]); ? Commented 7/07/2017 às 17:04

1 Resposta 1

0

Encontrei a solução. Criar uma variável ns

var ns : String;

ns := 'urn:OECD:StandardAuditFile-Tax:PT_1.04_01';

Este -> ns terá que ser declarado em todos os "node0"

ns := 'urn:OECD:StandardAuditFile-Tax:PT_1.04_01';

XML.Options := [doNodeAutoIndent];
RootNode := XML.AddChild('AuditFile');
RootNode.Attributes['xmlns:xsi'] := 'http://www.w3.org/2001/XMLSchema-instance';
RootNode.Attributes['xsi:schemaLocation'] := 'urn:OECD:StandardAuditFile-Tax:PT_1.04_01 .\SAFTPT1.04_01.xsd';

RootNode.DeclareNamespace('',ns);

Node0 := RootNode.AddChild('Header', ns);//add the task node
  addChildToNode(Node0, 'Version','1.04_01', 10, True);
  addChildToNode(Node0, 'CompanyID'                ,'11111111111111', 50, True);
  addChildToNode(Node0, 'TaxRegistrationNumber'    ,'222222222222222222222',  9, True);
Node0 := RootNode.AddChild('Semestre', ns);//add the task node
  addChildToNode(Node0, 'TaxAccountingBasis'       ,'F', 1, True );
  addChildToNode(Node0, 'CompanyName'              ,'444444444444444444444',100, True );  //Nome Registado
  addChildToNode(Node0, 'BusinessName'             ,'5555555555555555555555555555', 60, False );

Então o <Header> aparece limpo.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .