首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

请教数据库中的表数据怎么导出XML文件

2012-02-14 
请问数据库中的表数据如何导出XML文件请问数据库中的表数据如何生成XML文件,手工就可以。我现在打算把数据

请问数据库中的表数据如何导出XML文件
请问数据库中的表数据如何生成XML文件,手工就可以。我现在打算把数据放到txt中,导入到Sql   Server中去,然后再导出XML。需要的是一个XML文件,数据太多,手工输入工作量太大了。

[解决办法]
关键是定义xml格式,
比如
<tabledata>
<recordcount type= "int " value= "记录数 ">
<record>
<fieldname> 字段名 </fieldname>
<fieldtype> 字段类型 </fieldtype>
<fieldvalue> 字段值 </fieldvalue>
</record>
...
</tabledata>
[解决办法]
帮你顶下
[解决办法]
使用CDS导出到XML

倒出到文件:
cds1.SaveToFile(SaveDialog1.FileName, dfXML);

[解决办法]
ADOQuery1.SaveToFile( 'd:\xmlx.xml ', pfXML);
这样保存挺好的呀,不过肯定不是你自己想要的格式的,他还要导出表的格式信息一类的
如果非要自己的格式,那就自己写个函数了
[解决办法]
procedure TFrmPrintReport.DataToXmlAir(ReportName: string);
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;

热点排行