NativeXml (8):其它添加
NativeXml (8):其它添加
涂孟超 发表于3年前
NativeXml (8):其它添加
  • 发表于 3年前
  • 阅读 4
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   


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

共有 人打赏支持
粉丝 13
博文 2004
码字总数 14107
×
涂孟超
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: