我要把查询出来的结果生成XML的格式,怎么做?

jerrybao 2003-12-13 07:41:12
我要把查询出来的结果生成XML的格式,怎么做?
...全文
99 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
VeryOldMan 2003-12-17
  • 打赏
  • 举报
回复
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
entire 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
temp := FloatToStr(table.Fields[i].AsFloat)
else
temp := '0';
end;

ftBoolean:
begin
if table.Fields[i].Value then
temp:= 'True'
else
temp:= 'False';
end;

ftDate:
begin
if (not table.Fields[i].IsNull) or
(Length(Trim(table.Fields[i].AsString))
> 0) then
temp := FormatDateTime('MM/DD/YYYY',
table.Fields[i].AsDateTime)
else
//put a valid default date
temp:= '01/01/2000';
end;

ftDateTime:
begin
if (not table.Fields[i].IsNull) or
(Length(Trim(table.Fields[i].AsString))
> 0) then
temp := FormatDateTime('MM/DD/YYYY hh:nn:ss',
table.Fields[i].AsDateTime)
else
//Put a valid default date and time
temp := '01/01/2000 00:00:00';
end;

ftTime:
begin
if (not table.Fields[i].IsNull) or
(Length(Trim(table.Fields[i].AsString))
> 0) then
temp := FormatDateTime
('hh:nn:ss',
table.Fields[i].AsDateTime)
else
//Put a valid default time
temp := '00:00:00';
end;
end;
child1.appendChild(doc.createTextNode(temp));
end;
table.Next;
end;
doc.save(xml+'.xml');
memo1.lines.Append(doc.xml);
Result:=1;
except
on e:Exception do
Result:=-1;
end;
end;
VeryOldMan 2003-12-13
  • 打赏
  • 举报
回复
没有这么简单的方法。
能否利用ADODataSet的克浓方法复制过来,就得靠你自己得努力啦!
jerrybao 2003-12-13
  • 打赏
  • 举报
回复
如果不用ADO呢?
VeryOldMan 2003-12-13
  • 打赏
  • 举报
回复
如果用ADO的话:DataSet.SaveToFile('FileName',pfXML);即可。

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧