如何将数据保存为xml文件(100分)

  • 主题发起人 主题发起人 lkm.424
  • 开始时间 开始时间
对啊 就是ADOQuery1的SQL属性中的SQL语句啊
本来我写的是 select * from AA01
另外是不是跟我用的Access版本有关系啊 我用的是Access2003
 
那就不知道了,反正在我这边可以的!下面是我保存的XML文件:
- <xml xmlns:s=&quot;uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882&quot;
xmlns:dt=&quot;uuid:C2F41010-65B3-11d1-A29F-00AA00C14882&quot;
xmlns:rs=&quot;urn:schemas-microsoft-com:rowset&quot;
xmlns:z=&quot;#RowsetSchema&quot;>
- <s:Schema id=&quot;RowsetSchema&quot;>
- <s:ElementType name=&quot;row&quot;
content=&quot;eltOnly&quot;
rs:updatable=&quot;true&quot;>
- <s:AttributeType name=&quot;EmpNo&quot;
rs:number=&quot;1&quot;
rs:nullable=&quot;true&quot;
rs:maydefer=&quot;true&quot;
rs:writeunknown=&quot;true&quot;
rs:basetable=&quot;employee&quot;
rs:basecolumn=&quot;EmpNo&quot;
rs:keycolumn=&quot;true&quot;>
<s:datatype dt:type=&quot;int&quot;
dt:maxLength=&quot;4&quot;
rs:precision=&quot;10&quot;
rs:fixedlength=&quot;true&quot;
/>
</s:AttributeType>
- <s:AttributeType name=&quot;LastName&quot;
rs:number=&quot;2&quot;
rs:nullable=&quot;true&quot;
rs:maydefer=&quot;true&quot;
rs:writeunknown=&quot;true&quot;
rs:basetable=&quot;employee&quot;
rs:basecolumn=&quot;LastName&quot;>
<s:datatype dt:type=&quot;string&quot;
dt:maxLength=&quot;20&quot;
/>
</s:AttributeType>
- <s:AttributeType name=&quot;FirstName&quot;
rs:number=&quot;3&quot;
rs:nullable=&quot;true&quot;
rs:maydefer=&quot;true&quot;
rs:writeunknown=&quot;true&quot;
rs:basetable=&quot;employee&quot;
rs:basecolumn=&quot;FirstName&quot;>
<s:datatype dt:type=&quot;string&quot;
dt:maxLength=&quot;15&quot;
/>
</s:AttributeType>
- <s:AttributeType name=&quot;PhoneExt&quot;
rs:number=&quot;4&quot;
rs:nullable=&quot;true&quot;
rs:maydefer=&quot;true&quot;
rs:writeunknown=&quot;true&quot;
rs:basetable=&quot;employee&quot;
rs:basecolumn=&quot;PhoneExt&quot;>
<s:datatype dt:type=&quot;string&quot;
dt:maxLength=&quot;4&quot;
/>
</s:AttributeType>
- <s:AttributeType name=&quot;HireDate&quot;
rs:number=&quot;5&quot;
rs:nullable=&quot;true&quot;
rs:maydefer=&quot;true&quot;
rs:writeunknown=&quot;true&quot;
rs:basetable=&quot;employee&quot;
rs:basecolumn=&quot;HireDate&quot;>
<s:datatype dt:type=&quot;dateTime&quot;
rs:dbtype=&quot;variantdate&quot;
dt:maxLength=&quot;16&quot;
rs:fixedlength=&quot;true&quot;
/>
</s:AttributeType>
- <s:AttributeType name=&quot;Salary&quot;
rs:number=&quot;6&quot;
rs:nullable=&quot;true&quot;
rs:maydefer=&quot;true&quot;
rs:writeunknown=&quot;true&quot;
rs:basetable=&quot;employee&quot;
rs:basecolumn=&quot;Salary&quot;>
<s:datatype dt:type=&quot;float&quot;
dt:maxLength=&quot;8&quot;
rs:precision=&quot;15&quot;
rs:fixedlength=&quot;true&quot;
/>
</s:AttributeType>
<s:extends type=&quot;rs:rowbase&quot;
/>
</s:ElementType>
</s:Schema>
- <rs:data>
<z:row EmpNo=&quot;2&quot;
LastName=&quot;Nelson&quot;
FirstName=&quot;Roberto&quot;
PhoneExt=&quot;250&quot;
HireDate=&quot;1988-12-28T00:00:00&quot;
Salary=&quot;40000&quot;
/>
<z:row EmpNo=&quot;4&quot;
LastName=&quot;Young&quot;
FirstName=&quot;Bruce&quot;
PhoneExt=&quot;233&quot;
HireDate=&quot;1988-12-28T00:00:00&quot;
Salary=&quot;55500&quot;
/>
<z:row EmpNo=&quot;5&quot;
LastName=&quot;Lambert&quot;
FirstName=&quot;Kim&quot;
PhoneExt=&quot;22&quot;
HireDate=&quot;1989-02-06T00:00:00&quot;
Salary=&quot;25000&quot;
/>
<z:row EmpNo=&quot;8&quot;
LastName=&quot;Johnson&quot;
FirstName=&quot;Leslie&quot;
PhoneExt=&quot;410&quot;
HireDate=&quot;1989-04-05T00:00:00&quot;
Salary=&quot;25050&quot;
/>
<z:row EmpNo=&quot;9&quot;
LastName=&quot;Forest&quot;
FirstName=&quot;Phil&quot;
PhoneExt=&quot;229&quot;
HireDate=&quot;1989-04-17T00:00:00&quot;
Salary=&quot;25050&quot;
/>
<z:row EmpNo=&quot;11&quot;
LastName=&quot;Weston&quot;
FirstName=&quot;K. J.&quot;
PhoneExt=&quot;34&quot;
HireDate=&quot;1990-01-17T00:00:00&quot;
Salary=&quot;33292.9375&quot;
/>
<z:row EmpNo=&quot;12&quot;
LastName=&quot;Lee&quot;
FirstName=&quot;Terri&quot;
PhoneExt=&quot;256&quot;
HireDate=&quot;1990-05-01T00:00:00&quot;
Salary=&quot;45332&quot;
/>
<z:row EmpNo=&quot;14&quot;
LastName=&quot;Hall&quot;
FirstName=&quot;Stewart&quot;
PhoneExt=&quot;227&quot;
HireDate=&quot;1990-06-04T00:00:00&quot;
Salary=&quot;34482.625&quot;
/>
<z:row EmpNo=&quot;15&quot;
LastName=&quot;Young&quot;
FirstName=&quot;Katherine&quot;
PhoneExt=&quot;231&quot;
HireDate=&quot;1990-06-14T00:00:00&quot;
Salary=&quot;24400&quot;
/>
<z:row EmpNo=&quot;20&quot;
LastName=&quot;Papadopoulos&quot;
FirstName=&quot;Chris&quot;
PhoneExt=&quot;887&quot;
HireDate=&quot;1990-01-01T00:00:00&quot;
Salary=&quot;25050&quot;
/>
<z:row EmpNo=&quot;24&quot;
LastName=&quot;Fisher&quot;
FirstName=&quot;Pete&quot;
PhoneExt=&quot;888&quot;
HireDate=&quot;1990-09-12T00:00:00&quot;
Salary=&quot;23040&quot;
/>
<z:row EmpNo=&quot;28&quot;
LastName=&quot;Bennet&quot;
FirstName=&quot;Ann&quot;
PhoneExt=&quot;5&quot;
HireDate=&quot;1991-02-01T00:00:00&quot;
Salary=&quot;34482.800000000003&quot;
/>
<z:row EmpNo=&quot;29&quot;
LastName=&quot;De Souza&quot;
FirstName=&quot;Roger&quot;
PhoneExt=&quot;288&quot;
HireDate=&quot;1991-02-18T00:00:00&quot;
Salary=&quot;25500&quot;
/>
<z:row EmpNo=&quot;34&quot;
LastName=&quot;Baldwin&quot;
FirstName=&quot;Janet&quot;
PhoneExt=&quot;2&quot;
HireDate=&quot;1991-03-21T00:00:00&quot;
Salary=&quot;23300&quot;
/>
<z:row EmpNo=&quot;36&quot;
LastName=&quot;Reeves&quot;
FirstName=&quot;Roger&quot;
PhoneExt=&quot;6&quot;
HireDate=&quot;1991-04-25T00:00:00&quot;
Salary=&quot;33620&quot;
/>
<z:row EmpNo=&quot;37&quot;
LastName=&quot;Stansbury&quot;
FirstName=&quot;Willie&quot;
PhoneExt=&quot;7&quot;
HireDate=&quot;1991-04-25T00:00:00&quot;
Salary=&quot;39224&quot;
/>
<z:row EmpNo=&quot;44&quot;
LastName=&quot;Phong&quot;
FirstName=&quot;Leslie&quot;
PhoneExt=&quot;216&quot;
HireDate=&quot;1991-06-03T00:00:00&quot;
Salary=&quot;40350&quot;
/>
<z:row EmpNo=&quot;45&quot;
LastName=&quot;Ramanathan&quot;
FirstName=&quot;Ashok&quot;
PhoneExt=&quot;209&quot;
HireDate=&quot;1991-08-01T00:00:00&quot;
Salary=&quot;33292.940000000002&quot;
/>
<z:row EmpNo=&quot;46&quot;
LastName=&quot;Steadman&quot;
FirstName=&quot;Walter&quot;
PhoneExt=&quot;210&quot;
HireDate=&quot;1991-08-09T00:00:00&quot;
Salary=&quot;19599&quot;
/>
<z:row EmpNo=&quot;52&quot;
LastName=&quot;Nordstrom&quot;
FirstName=&quot;Carol&quot;
PhoneExt=&quot;420&quot;
HireDate=&quot;1991-10-02T00:00:00&quot;
Salary=&quot;4500&quot;
/>
<z:row EmpNo=&quot;61&quot;
LastName=&quot;Leung&quot;
FirstName=&quot;Luke&quot;
PhoneExt=&quot;3&quot;
HireDate=&quot;1992-02-18T00:00:00&quot;
Salary=&quot;34500&quot;
/>
<z:row EmpNo=&quot;65&quot;
LastName=&quot;O'Brien&quot;
FirstName=&quot;Sue Anne&quot;
PhoneExt=&quot;877&quot;
HireDate=&quot;1992-03-23T00:00:00&quot;
Salary=&quot;31275&quot;
/>
<z:row EmpNo=&quot;71&quot;
LastName=&quot;Burbank&quot;
FirstName=&quot;Jennifer M.&quot;
PhoneExt=&quot;289&quot;
HireDate=&quot;1992-04-15T00:00:00&quot;
Salary=&quot;45332&quot;
/>
<z:row EmpNo=&quot;72&quot;
LastName=&quot;Sutherland&quot;
FirstName=&quot;Claudia&quot;
HireDate=&quot;1992-04-20T00:00:00&quot;
Salary=&quot;35699&quot;
/>
<z:row EmpNo=&quot;83&quot;
LastName=&quot;Bishop&quot;
FirstName=&quot;Dana&quot;
PhoneExt=&quot;290&quot;
HireDate=&quot;1992-06-01T00:00:00&quot;
Salary=&quot;45000&quot;
/>
<z:row EmpNo=&quot;85&quot;
LastName=&quot;MacDonald&quot;
FirstName=&quot;Mary S.&quot;
PhoneExt=&quot;477&quot;
HireDate=&quot;1992-06-01T00:00:00&quot;
Salary=&quot;35699&quot;
/>
<z:row EmpNo=&quot;94&quot;
LastName=&quot;Williams&quot;
FirstName=&quot;Randy&quot;
PhoneExt=&quot;892&quot;
HireDate=&quot;1992-08-08T00:00:00&quot;
Salary=&quot;28900&quot;
/>
<z:row EmpNo=&quot;105&quot;
LastName=&quot;Bender&quot;
FirstName=&quot;Oliver H.&quot;
PhoneExt=&quot;255&quot;
HireDate=&quot;1992-10-08T00:00:00&quot;
Salary=&quot;36799&quot;
/>
<z:row EmpNo=&quot;107&quot;
LastName=&quot;Cook&quot;
FirstName=&quot;Kevin&quot;
PhoneExt=&quot;894&quot;
HireDate=&quot;1993-02-01T00:00:00&quot;
Salary=&quot;35500&quot;
/>
<z:row EmpNo=&quot;109&quot;
LastName=&quot;Brown&quot;
FirstName=&quot;Kelly&quot;
PhoneExt=&quot;202&quot;
HireDate=&quot;1993-02-04T00:00:00&quot;
Salary=&quot;27000&quot;
/>
<z:row EmpNo=&quot;110&quot;
LastName=&quot;Ichida&quot;
FirstName=&quot;Yuki&quot;
PhoneExt=&quot;22&quot;
HireDate=&quot;1993-02-04T00:00:00&quot;
Salary=&quot;25689&quot;
/>
<z:row EmpNo=&quot;113&quot;
LastName=&quot;Page&quot;
FirstName=&quot;Mary&quot;
PhoneExt=&quot;845&quot;
HireDate=&quot;1993-04-12T00:00:00&quot;
Salary=&quot;48000&quot;
/>
<z:row EmpNo=&quot;114&quot;
LastName=&quot;Parker&quot;
FirstName=&quot;Bill&quot;
PhoneExt=&quot;247&quot;
HireDate=&quot;1993-06-01T00:00:00&quot;
Salary=&quot;35000&quot;
/>
<z:row EmpNo=&quot;118&quot;
LastName=&quot;Yamamoto&quot;
FirstName=&quot;Takashi&quot;
PhoneExt=&quot;23&quot;
HireDate=&quot;1993-07-01T00:00:00&quot;
Salary=&quot;32500&quot;
/>
<z:row EmpNo=&quot;121&quot;
LastName=&quot;Ferrari&quot;
FirstName=&quot;Roberto&quot;
PhoneExt=&quot;1&quot;
HireDate=&quot;1993-07-12T00:00:00&quot;
Salary=&quot;40500&quot;
/>
<z:row EmpNo=&quot;127&quot;
LastName=&quot;Yanowski&quot;
FirstName=&quot;Michael&quot;
PhoneExt=&quot;492&quot;
HireDate=&quot;1993-08-09T00:00:00&quot;
Salary=&quot;44000&quot;
/>
<z:row EmpNo=&quot;134&quot;
LastName=&quot;Glon&quot;
FirstName=&quot;Jacques&quot;
HireDate=&quot;1993-08-23T00:00:00&quot;
Salary=&quot;24855&quot;
/>
<z:row EmpNo=&quot;136&quot;
LastName=&quot;Johnson&quot;
FirstName=&quot;Scott&quot;
PhoneExt=&quot;265&quot;
HireDate=&quot;1993-09-13T00:00:00&quot;
Salary=&quot;30588.990000000002&quot;
/>
<z:row EmpNo=&quot;138&quot;
LastName=&quot;Green&quot;
FirstName=&quot;T.J.&quot;
PhoneExt=&quot;218&quot;
HireDate=&quot;1993-11-01T00:00:00&quot;
Salary=&quot;36000&quot;
/>
<z:row EmpNo=&quot;141&quot;
LastName=&quot;Osborne&quot;
FirstName=&quot;Pierre&quot;
HireDate=&quot;1994-01-03T00:00:00&quot;
Salary=&quot;35600&quot;
/>
<z:row EmpNo=&quot;144&quot;
LastName=&quot;Montgomery&quot;
FirstName=&quot;John&quot;
PhoneExt=&quot;820&quot;
HireDate=&quot;1994-03-30T00:00:00&quot;
Salary=&quot;35699&quot;
/>
<z:row EmpNo=&quot;145&quot;
LastName=&quot;Guckenheimer&quot;
FirstName=&quot;Mark&quot;
PhoneExt=&quot;221&quot;
HireDate=&quot;1994-05-02T00:00:00&quot;
Salary=&quot;32000&quot;
/>
</rs:data>
</xml>
 
royal1442的方法我也试过了 在SQL Server下可以Access下还是不行啊
我的机器环境试Win2000Server +SP4
Delphi7,office2003
 
报错了嘛?
 
同样的错误 !!
 
我把文件名称改为:'c:/x.xml' 还是那个错误
 
你把主要的源码贴出来看看啊!◎
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ADOTable1: TADOTable;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
ADOQuery1.LoadFromFile('C:/x.XML');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
adoQuery1.SaveToFile('C:/x.XML', pfXML);
end;

end.

就是两个按钮的click2事件
 
你把Adoquery1关闭呢
 
ADOQuery1确定已经打开了吗?
 
那样也不行的,提示'Cannot perform this operation on a closed dataset '
 
ADOQuery1 必须在Active 为True的时候才能保存!
 
procedure TForm1.Button1Click(Sender: TObject);
begin
adoQuery1.Open:=True;
adoQuery1.SaveToFile('C:/x.XML', pfXML);
end;
 
晕倒了!“adoQuery1.Open:=True;”这样写不报错?
 
不好意思 见笑了
procedure TForm1.Button1Click(Sender: TObject);
begin
adoQuery1.Open;
adoQuery1.SaveToFile('C:/x.XML', pfXML);
end;
 
以下摘自ADODB.pas单元,应该可以支持Access数据库:
procedure TCustomADODataSet.SaveToFile(const FileName: WideString;
Format: TPersistFormat);
begin
CheckBrowseMode;
if FileExists(FileName) then
DeleteFile(FileName);
if LowerCase(ExtractFileExt(FileName)) = '.xml' then
Format := pfXML;
Recordset.Save(FileName, PersistFormatEnum(Format));
CursorPosChanged;
end;
 
谢谢 chnplzh, 这个我已经看过了!可还是不知道为什么出错
我在别的机器上也试验了 也试不行
 
adoQuery1能正确Open,且包含数据吗?
 
我看过了 包含数据啊
我用dbGrid显示的啊
 
问题解决了。发分
 
后退
顶部