Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 4647|回复: 1

写xml文件的方法DEMO

[复制链接]

该用户从未签到

发表于 2009-6-22 16:49:15 | 显示全部楼层 |阅读模式
  1. var
  2.   xdoc: TXMLDocument;                                  // variable to document
  3.   noraiz, nopai, nofilho: TDOMNode;                    // variable to nodes
  4. begin
  5.   //create a document
  6.   xdoc := TXMLDocument.create;
  7.   xdoc.Encoding := 'utf-8';
  8.   //create a root node
  9.   noraiz := xdoc.CreateElement('cadastro');
  10.   Xdoc.Appendchild(noraiz);                           // save root node
  11.   //create a parent node
  12.   noraiz:= xdoc.DocumentElement;
  13.   nopai := xdoc.CreateElement('usuario');
  14.   TDOMElement(nopai).SetAttribute(ANSITOUTF8('你'), ANSITOUTF8('好'));       // create atributes to parent node
  15.   noraiz.Appendchild(nopai);                          // save parent node
  16.   //create a child node
  17.   nopai := xdoc.CreateElement('nome');                // create a child node
  18.   //TDOMElement(nopai).SetAttribute('sexo', 'M');     // create atributes
  19.   nofilho := xdoc.CreateTextNode('Fernando');         // insert a value to node
  20.   nopai.Appendchild(nofilho);                         // save node
  21.   noraiz.ChildNodes.Item[0].AppendChild(nopai);       // insert child node in respective parent node
  22.   //create a child node
  23.   nopai := xdoc.CreateElement('idade');               // create a child node
  24.   //TDOMElement(nopai).SetAttribute('ano', '1976');   // create atributes
  25.   nofilho := xdoc.CreateTextNode('32');               // insert a value to node
  26.   nopai.Appendchild(nofilho);                         // save node
  27.   noraiz.ChildNodes.Item[0].AppendChild(nopai);       // insert a childnode in respective parent node
  28.   writeXMLFile(xDoc,'teste.xml');                     // write to XML
  29.   Xdoc.free;
复制代码
回复

使用道具 举报

该用户从未签到

发表于 2009-7-21 11:32:35 | 显示全部楼层
这个不会是像Delphi中的那样,也是COM吧?
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-5-3 10:27 , Processed in 0.026411 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表