xxxxxxxxxx
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>
*****************************************}