问题
I am developing a Delphi application that needs to pick up the rows from a period of work and convert them to a single XML file in order to upload to a 3rd party web-service.
Is there any component or library available to do that? If not, what is the best approach of code to build that DB2XML conversor?
I noticed that most XML questions are about how to convert it to another type of data.
Note: the database will be MySQL or Firebird.
回答1:
You can use the TDataSetProvider component to fill a TClientDataSet with the TDataSet contents and then use the SaveToFile method to create the xml file.
Try this sample
procedure DataSetToXML(DataSet : TDataSet; const FileName:string);
var
LProvider : TDataSetProvider;
LClient : TClientDataSet;
begin
LProvider:=TDataSetProvider.Create(nil);
try
LProvider.DataSet:=DataSet;
LClient:=TClientDataSet.Create(nil);
try
DataSet.DisableControls;
try
if not DataSet.Active then
DataSet.Active:=True;
LClient.SetProvider(LProvider);
LClient.Active:=True;
LClient.SaveToFile(FileName, dfXMLUTF8);
finally
DataSet.EnableControls;
end;
finally
LClient.Free;
end;
finally
LProvider.Free;
end;
end;
回答2:
You could put your table in a TClientDataSet, and then export as XML using the XMLData property.
来源:https://stackoverflow.com/questions/12150775/how-to-convert-rows-of-a-database-query-to-a-xml-file