我要把查询出来的结果生成XML的格式,怎么做?
解决方案 »
- 为何列表框选中一项后不能在编辑框出现?
- 问一个Access中的超简单的Select语句
- 大侠们:错误too many consecutive 怎么回事?
- 苦解 ADOQUERY + ACCESS 的刷新问题
- 怎么样声明有一个参数是数组的过程?
- udpserver,udpclient 用delphi7 7封装在dll 里,出现的问题
- 武汉的爱好IT业的朋友请来转转:)给见面礼啦
- 为什么我编写的ActivexForm ocx控件在客户端总是不停要求我注册呢?(我已经做了数字签名)
- 如何使用橡皮筋的方式画一个矩形,最好有源码??
- 如何实现StatusBar.Panels[1].text在Panels[1]范围内的平滑移动?
- 给个意见,谢谢!
- 用客户端调用COM进程内服务器时出错:加载类型库/Dll出错
能否利用ADODataSet的克浓方法复制过来,就得靠你自己得努力啦!
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;