remove Attribute from a Node in NexXMLDocument in DELPHI

1

I created an XML Document, when creating the 2nd. Node 'Header' comes with the attribute of the previous node.

The Node is created as <Header xmlns=""> how can I remove the xmlns="" from the Node

I used the following code

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 );

The result was:

<?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>

How to do for <Header xmlns=""> <Header>     

asked by anonymous 07.07.2017 / 01:38

1 answer

0

I found the solution. Create a ns variable

var ns: String;

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

This - > ns will have to be declared on all "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 );

Then <Header> appears clean.

    
09.07.2017 / 10:24