请问数据库中的表数据如何生成XML文件,手工就可以。我现在打算把数据放到txt中,导入到Sql Server中去,然后再导出XML。需要的是一个XML文件,数据太多,手工输入工作量太大了。
解决方案 »
- 如何判断pagecontrol下的TabSheet是否打开还是关闭
- 高分求教!!急急急!!!!!!!!
- 如果动态绑定控件的TEXT,VALUE的值呢?
- 怎么实现这样的界面效果!
- Delphi DBGrid 控件水平滚动条问题
- 某人不才,问诸位如何让自己的程序不被运行两次?(分多多)
- 用delphi实现在WORD中插入表格,如何实现???
- 我的DBgridEh组件出问题,DBgridEh.res,EHLibReg.dcr丢失!!谁有,给分!再线等待
- 最容易的问题
- 几个Delphi的Tips,其中一个很有用哦!
- 64位vista下驱动安装
- QuickRep中的TQRDBText自动换行问题,请高手帮忙!急啊!
比如
<tabledata>
<recordcount type="int" value="记录数">
<record>
<fieldname>字段名</fieldname>
<fieldtype>字段类型</fieldtype>
<fieldvalue>字段值</fieldvalue>
</record>
...
</tabledata>
<sss>
<学生>
<name>张三</name>
<age>年龄</age>
<学生>
</sss>
结果用adoquery的saveAsFile,导出的乱七八糟的
如何把姓名等于张三的所有节点找出来?比如三年级有个张三,五年级还有个张三,这两个都要找出来
cds1.SaveToFile(SaveDialog1.FileName, dfXML);
这样保存挺好的呀,不过肯定不是你自己想要的格式的,他还要导出表的格式信息一类的
如果非要自己的格式,那就自己写个函数了
var
Root :IXMLNode; //指向XML根结点
Parent_Node :IXMLNode;
Child_node :IXMLNode;
i :Integer;
ReportAllName: string;
begin
XMLDocument1.Active :=true; //激活OutXMLDoc,自动初始化空的XML文档
XMLDocument1.Encoding :='UTF-8'; //设置字符集
Root :=XMLDocument1.AddChild('clk_manifest'); //建根结点 //Departure Date Time of the ferry
Root.Attributes['departure_date'] := FormatDateTime('yyyy/mm/dd',DateTimePicker1.DateTime)+' '+FlatComboBox1.Text; //File name of the XML file
Root.Attributes['file_prefix'] :='SA_'+FormatDateTime('YYMMDDhhmm',DateTimePicker1.DateTime)+'_ZYK'; //Total number of On board Luggage
Root.Attributes['onb_luggage'] :=Label15.Caption; //Destination
Root.Attributes['port'] :='CLK'; //Total number of passengers = psg_noshow + psgonboard
Root.Attributes['psg_count'] :=Label9.Caption; //Total number of no shows
Root.Attributes['psg_noshow'] :='0'; //Total number of on-board passengers
Root.Attributes['psg_onboard'] :=Label9.Caption; //The ship route description
Root.Attributes['route'] :='Manifest of Passengers Bound for SheKou to CLK'; //Total number of Tag through onboard luggage
Root.Attributes['tagthru_onboard'] :=Label18.Caption; //Total number of Tag through
Root.Attributes['tagthru_total'] :=Label18.Caption; //Total number of Unclaimed tag through luggage
Root.Attributes['tagthru_unclaim'] :='0'; //Total number of baggage = onb_luggage + uncl_luggage
Root.Attributes['total_baggage'] :=Label15.Caption; //Trip Number (Ferry Code)
Root.Attributes['trip_no'] :=Label4.Caption; //Total number of unclaimed luggage
Root.Attributes['uncl_luggage'] :='0'; //Create_Date of the file
Root.Attributes['Create_Date'] :=FormatDateTime('YYYYMMDDhhmmss',now); Root.Attributes['xmlns:xsi'] :='http://www.w3.org/2001/XMLSchema-instance';
Root.Attributes['xsi:noNamespaceSchemaLocation'] :='_template.xsd'; ADOQuery1.First; for i :=0 to ADOQuery1.RecordCount do
begin
Parent_Node :=Root.AddChild('clk_manifest_row'); //根结点后添加一个Clk_manifest_row结点
Child_Node :=Parent_Node.AddChild('index'); //Clk_manifest_row结点后添加一个Index结点
Child_Node.Text :=IntToStr(ADOQuery1.RecNo); //设置Index的文本值 Child_Node :=Parent_Node.AddChild('carrier_no');
Child_Node.Text :=ADOQuery1.fieldbyname('Camer').AsString; Child_Node :=Parent_Node.AddChild('flight_no');
Child_Node.Text :=ADOQuery1.fieldbyname('FlightNo').AsString; Child_Node :=Parent_Node.AddChild('reservation_no');
Child_Node.Text :=ADOQuery1.fieldbyname('ShipTicketNO').AsString; Child_Node :=Parent_Node.AddChild('surname');
Child_Node.Text :=ADOQuery1.fieldbyname('SurName').AsString; Child_Node :=Parent_Node.AddChild('given_name');
Child_Node.Text :=ADOQuery1.fieldbyname('GivenName').AsString; Child_Node :=Parent_Node.AddChild('passport_no');
Child_Node.Text :=ADOQuery1.fieldbyname('PassportNo').AsString; Child_Node :=Parent_Node.AddChild('yob');
Child_Node.Text :=FormatDateTime('yyyy',ADOQuery1.fieldbyname('DateOfBidh').AsDateTime); Child_Node :=Parent_Node.AddChild('nationality');
Child_Node.Text :=ADOQuery1.fieldbyname('Nationality').AsString; Child_Node :=Parent_Node.AddChild('destination');
Child_Node.Text :=ADOQuery1.fieldbyname('Dest').AsString; Child_Node :=Parent_Node.AddChild('origin');
Child_Node.Text :=ADOQuery1.fieldbyname('Origin').AsString; Child_Node :=Parent_Node.AddChild('no_of_luggage');
Child_Node.Text :=ADOQuery1.fieldbyname('Luggage').AsString; Child_Node :=Parent_Node.AddChild('luggage_tag_no');
Child_Node.Text :=ADOQuery1.fieldbyname('LuggageTag').AsString; Child_Node :=Parent_Node.AddChild('luggage_weight');
Child_Node.Text :=ADOQuery1.fieldbyname('Weight').AsString; Child_Node :=Parent_Node.AddChild('boarding_status');
Child_Node.Text :='OK'; Child_Node :=Parent_Node.AddChild('luggage_status');
Child_Node.Text :='ONB'; Child_Node :=Parent_Node.AddChild('tax_refund_tag');
Child_Node.Text :=ADOQuery1.fieldbyname('FlightNo').AsString; Child_Node :=Parent_Node.AddChild('tax_refund_datetime');
Child_Node.Text :=''; ADOQuery1.Next;
end; XMLDocument1.SaveToFile(ReportName); XMLDocument1.Active :=False;
end;