uses NativeXML;
procedure TForm1.Button1Click(Sender: TObject);
var
xml: TNativeXML;
node: TXMLNode;
begin
xml := TNativeXML.CreateName('List');
xml.XMLFormat := xfReadable;
node := XML.NodeNewTextType('注釋名稱', '注釋內容', xeComment);
XML.Root.NodeAdd(node);
node := XML.NodeNewTextType('item', '張三', xeElement);
XML.Root.NodeAdd(node);
Memo1.Text := XML.WriteToString;
XML.Free;
end;
{***************************************
<?XML version="1.0" encoding="UTF-8"?>
<List><!--注釋內容-->
<item>張三</item>
</List>
*****************************************}
procedure TForm1.Button2Click(Sender: TObject);
var
xml: TNativeXML;
node: TXMLNode;
begin
xml := TNativeXML.CreateName('List');
xml.XMLFormat := xfReadable;
node := xml.NodeNewTextType('item', '張三', xeElement, [xml.AttrText('ID', '1'), XML.AttrInt('age', 11)]);
XML.Root.NodeAdd(node);
Memo1.Text := XML.WriteToString;
XML.Free;
end;
{***************************************
<?XML version="1.0" encoding="UTF-8"?>
<List>
<item ID="1" age="11">張三</item>
</List>
*****************************************}
procedure TForm1.Button3Click(Sender: TObject);
var
xml: TNativeXML;
node: TXMLNode;
begin
xml := TNativeXML.CreateName('List');
xml.XMLFormat := xfReadable;
node := xml.NodeNewTextTypeAttr('item', '', xeElement, [xml.AttrText('ID', '1')], [xml.NodeNewText('name', '張三'), XML.NodeNewInt('age', 11)]);
XML.Root.NodeAdd(node);
Memo1.Text := XML.WriteToString;
XML.Free;
end;
{***************************************
<?XML version="1.0" encoding="UTF-8"?>
<List>
<item ID="1">
<name>張三</name>
<age>11</age>
</item>
</List>
*****************************************}
procedure TForm1.Button4Click(Sender: TObject);
var
xml: TNativeXML;
node: TXMLNode;
begin
xml := TNativeXML.CreateName('List');
xml.XMLFormat := xfReadable;
node := XML.Root.NodeNew('Data1');
node.NodeAdd(XML.NodeNewTextType('DataName', 'XXXXXXXXXXXX', xeCData));
Memo1.Text := XML.WriteToString;
XML.Free;
end;
{***************************************
<?XML version="1.0" encoding="UTF-8"?>
<List>
<Data1><![CDATA[XXXXXXXXXXXX]]></Data1>
</List>
*****************************************}
procedure TForm1.Button5Click(Sender: TObject);
var
xml: TNativeXML;
begin
xml := TNativeXML.CreateName('List');
xml.XMLFormat := xfReadable;
xml.Root.NodeAdd(XML.NodeNewTextType('aaa', 'AAAAAAA', xeElement));
xml.Root.NodeAdd(XML.NodeNewTextType('bbb', 'BBBBBBB', xeAttribute));
xml.Root.NodeAdd(XML.NodeNewTextType('ccc', 'CCCCCCC', xeComment));
xml.Root.NodeAdd(XML.NodeNewTextType('ddd', 'DDDDDDD', xeCData));
xml.Root.NodeAdd(XML.NodeNewTextType('eee', 'EEEEEEE', xeCondSection));
xml.Root.NodeAdd(XML.NodeNewTextType('fff', 'FFFFFFF', xeStylesheet));
xml.Root.NodeAdd(XML.NodeNewTextType('ggg', 'GGGGGGG', xeDocType));
xml.Root.NodeAdd(XML.NodeNewTextType('hhh', 'HHHHHHH', xeDtdElement));
xml.Root.NodeAdd(XML.NodeNewTextType('iii', 'IIIIIII', xeDtdAttList));
xml.Root.NodeAdd(XML.NodeNewTextType('jjj', 'JJJJJJJ', xeDtdEntity));
xml.Root.NodeAdd(XML.NodeNewTextType('kkk', 'KKKKKKK', xeDtdNotation));
xml.Root.NodeAdd(XML.NodeNewTextType('lll', 'LLLLLLL', xeInstruction));
xml.Root.NodeAdd(XML.NodeNewTextType('mmm', 'MMMMMMM', xeCharData));
xml.Root.NodeAdd(XML.NodeNewTextType('nnn', 'NNNNNNN', xeWhiteSpace));
xml.Root.NodeAdd(XML.NodeNewTextType('ooo', 'OOOOOOO', xeQuotedText));
Memo1.Text := XML.WriteToString;
XML.Free;
end;
{***************************************
<?XML version="1.0" encoding="UTF-8"?>
<List bbb="BBBBBBB"NNNNNNN>
<aaa>AAAAAAA</aaa>
<!--CCCCCCC-->
<![CDATA[DDDDDDD]]>
<!--EEEEEEE-->
<?XML-stylesheetFFFFFFF?>
[
GGGGGGG]>
<!ELEMENT hhh HHHHHHH>
<!ATTLIST iii IIIIIII>
<!ENTITY jjj JJJJJJJ>
<!NOTATION kkk KKKKKKK>
<?LLLLLLL?>
MMMMMMM
"OOOOOOO"
</List>
*****************************************}