如何用xmldocument生成一个xml文件 现在只会用其中load一个文件,不知能不能用些控件生成一个文件,另问其中的savetostream怎么用 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit uExport;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, XMLDoc, XMLIntf;type TfrmExport=class(TForm) Button1:TButton; Label10:TLabel; edTo:TEdit; procedure Button1Click(Sender:TObject); procedure FormCreate(Sender: TObject); end;var frmExport:TfrmExport; xml:TXMLDocument; Root, Son1:IXMLNode;implementation{$R *.dfm}procedure addOne(var son, par:IXMLNode; chs, atn1, atv1, atn2, atv2:string);begin son:=par.AddChild(chs); if (atn1<>'')and(atv1<>'') then son.Attributes[atn1]:=atv1; if (atn2<>'')and(atv2<>'') then son.Attributes[atn2]:=atv2;end;function UploadOne(xmlPath, idxName1, idxVal1, idxName2, idxVal2, idxName3, idxVal3, idxName4, idxVal4, idxName5, idxVal5 :string ):Boolean;var Son2, Son3, Son4:IXMLNode;begin xml:=TXMLDocument.Create(nil); xml.Active:=True; xml.Encoding:='utf-8'; Root:=xml.AddChild('export-list'); addOne(Son1, Root, 'add-list', '', '', '', ''); addOne(Son2, Son1, 'category', 'name', 'Table1', '', ''); addOne(Son3, Son2, 'attr', 'name', idxName1, '', ''); addOne(Son3, Son2, 'attr', 'name', idxName2, '', ''); addOne(Son3, Son2, 'attr', 'name', idxName3, '', ''); addOne(Son3, Son2, 'attr', 'name', idxName4, '', ''); addOne(Son3, Son2, 'attr', 'name', idxName5, '', ''); addOne(Son2, Son1, 'object', 'folder', 'Corporate Library remotePath', 'name', 'SourceFile'); addOne(Son3, Son2, 'source', 'url', 'sourcePath', '', ''); addOne(Son3, Son2, 'category', 'name', 'Table1', '', ''); addOne(Son4, Son3, 'attr', 'name', idxName1, 'value', idxVal1); addOne(Son4, Son3, 'attr', 'name', idxName2, 'value', idxVal2); addOne(Son4, Son3, 'attr', 'name', idxName3, 'value', idxVal3); addOne(Son4, Son3, 'attr', 'name', idxName4, 'value', idxVal4); addOne(Son4, Son3, 'attr', 'name', idxName5, 'value', idxVal5); xml.SaveToFile(xmlPath); result:=True;end;procedure TfrmExport.Button1Click(Sender:TObject);begin if not DirectoryExists(edTo.Text) then begin ShowMessage('Target Path not exist.'); exit; end; screen.Cursor:=crHourGlass; UploadOne(edTo.Text+'\000001.xml', 'edIdxN1.Text', 'edIndex1.Text', 'edIdxN2.Text', 'edIndex2.Text', 'edIdxN3.Text', 'edIndex3.Text', 'edIdxN4.Text', 'edIndex4.Text', 'edIdxN5.Text', 'edIndex5.Text', ); screen.Cursor:=crDefault; ShowMessage('Finished. ');end;procedure TfrmExport.FormCreate(Sender: TObject);begin edto.Text:='c:\temp';end;end. 上面能就xml.savetostream给个示例吗? 100分求解 动态设定ado的connectionstring的问题? fastreoprt基础问题?如何弹出打印设置对话框 如何用程序控制键盘上的CapsLock键,NumLock键?急!!! COM 远程调用的问题 数据表修改出错,帮帮我!!谢谢了先 怎样实现类似OICQ的那种可以点击弹动的菜单? 哪位大哥有TeeTree控件?有急用,谢谢 谁有DELPHI的类似控件参考手册的书? 高分请教!如何获取磁盘的文件格式? 请教一个小问题? Delphi版人气越来越差了 人都跑哪儿去了?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XMLDoc, XMLIntf;type
TfrmExport=class(TForm)
Button1:TButton;
Label10:TLabel;
edTo:TEdit;
procedure Button1Click(Sender:TObject);
procedure FormCreate(Sender: TObject);
end;
var
frmExport:TfrmExport;
xml:TXMLDocument; Root, Son1:IXMLNode;
implementation
{$R *.dfm}
procedure addOne(var son, par:IXMLNode; chs, atn1, atv1, atn2, atv2:string);
begin
son:=par.AddChild(chs);
if (atn1<>'')and(atv1<>'') then son.Attributes[atn1]:=atv1;
if (atn2<>'')and(atv2<>'') then son.Attributes[atn2]:=atv2;
end;function UploadOne(xmlPath,
idxName1, idxVal1,
idxName2, idxVal2,
idxName3, idxVal3,
idxName4, idxVal4,
idxName5, idxVal5
:string
):Boolean;
var Son2, Son3, Son4:IXMLNode;
begin xml:=TXMLDocument.Create(nil);
xml.Active:=True;
xml.Encoding:='utf-8';
Root:=xml.AddChild('export-list');
addOne(Son1, Root, 'add-list', '', '', '', ''); addOne(Son2, Son1, 'category', 'name', 'Table1', '', ''); addOne(Son3, Son2, 'attr', 'name', idxName1, '', '');
addOne(Son3, Son2, 'attr', 'name', idxName2, '', '');
addOne(Son3, Son2, 'attr', 'name', idxName3, '', '');
addOne(Son3, Son2, 'attr', 'name', idxName4, '', '');
addOne(Son3, Son2, 'attr', 'name', idxName5, '', '');
addOne(Son2, Son1, 'object', 'folder', 'Corporate Library remotePath', 'name', 'SourceFile'); addOne(Son3, Son2, 'source', 'url', 'sourcePath', '', '');
addOne(Son3, Son2, 'category', 'name', 'Table1', '', ''); addOne(Son4, Son3, 'attr', 'name', idxName1, 'value', idxVal1);
addOne(Son4, Son3, 'attr', 'name', idxName2, 'value', idxVal2);
addOne(Son4, Son3, 'attr', 'name', idxName3, 'value', idxVal3);
addOne(Son4, Son3, 'attr', 'name', idxName4, 'value', idxVal4);
addOne(Son4, Son3, 'attr', 'name', idxName5, 'value', idxVal5); xml.SaveToFile(xmlPath);
result:=True;
end;procedure TfrmExport.Button1Click(Sender:TObject);
begin
if not DirectoryExists(edTo.Text) then begin
ShowMessage('Target Path not exist.');
exit;
end; screen.Cursor:=crHourGlass; UploadOne(edTo.Text+'\000001.xml',
'edIdxN1.Text', 'edIndex1.Text',
'edIdxN2.Text', 'edIndex2.Text',
'edIdxN3.Text', 'edIndex3.Text',
'edIdxN4.Text', 'edIndex4.Text',
'edIdxN5.Text', 'edIndex5.Text',
); screen.Cursor:=crDefault;
ShowMessage('Finished. ');
end;procedure TfrmExport.FormCreate(Sender: TObject);
begin
edto.Text:='c:\temp';
end;end.