程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> NativeXml (8):其它添加

NativeXml (8):其它添加

編輯:Delphi

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


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved