text1,text2 : ixmldomtext;
nlist : ixmldomnodelist;
datarecord : string;
添加makexml函数到你的单元。它将通过读取dbdemos中contry表中的数据生成一个xml文件。
function tform1.makexml(table:ttable):integer;
var
i : integer;
xml,temp : string;
begin
try
table.close;
table.open;
xml := table.tablename;
doc := createoleobject('microsoft.xmldom') as ixmldomdocument;
//set the root name of the xml file as that of the table name.
//in this case "country"
root := doc.createelement(xml);
doc.appendchild(root);
//this while loop will go through the entaire table to generate the xml file
while not table.eof do
begin
//adds the first level children , records
child:= doc.createelement('records');
root.appendchild(child);
for i:=0 to table.fieldcount-1 do
begin
//adds second level children
child1:=doc.createelement(table.fields[i].fieldname);
child.appendchild(child1);
//check field types
case tfieldtype(ord(table.fields[i].datatype)) of
ftstring:
begin
if table.fields[i].asstring ='' then
temp :='null' //put a default string
else
temp := table.fields[i].asstring;
end;
ftinteger, ftword, ftsmallint:
begin
if table.fields[i].asinteger > 0 then
temp := inttostr(table.fields[i].asinteger)
else
temp := '0';
end;
ftfloat, ftcurrency, ftbcd:
begin
if table.fields[i].asfloat > 0 then