Hi
DP'ler,
hier das vorläufige Ergebnis (ist noch nicht fertig) meiner Bemühungen eine
Access Datenbank in ein
XML Dokument zu überführen.
Ich habe das Ganze weitgehend universell geschrieben, sodass man, im Prinzip, jede
Access Datenbank damit umwnandeln kann.
b:=true dient nur als Platzhalter für die fehlenden Typdefinitionen.
Realisiert wurde das Ganze unter Verwendung von Tclientdataset.
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var j:integer;b:boolean;ClientDataSet:TClientDataSet;
begin
ClientDataSet:=TClientDataSet.Create(self);
If fileexists('d:\Transfer.xml') then DeleteFile('d:\Transfer.xml');
ClientDataSet.FileName:='';
begin
For j:=0 to ADOTable1.FieldList.Count-1 do
case ADOTable1.FieldList.Fields[j].DataType of
ftUnknown: b:=true;
ftString: ClientDataSet.FieldDefs.Add(ADOTable1.FieldList.Fields[j].FieldName, ftString, ADOTable1.FieldList.Fields[j].Size, FALSE);
ftWideString: ClientDataSet.FieldDefs.Add(ADOTable1.FieldList.Fields[j].FieldName, ftString, ADOTable1.FieldList.Fields[j].Size, FALSE);
ftInteger: ClientDataSet.FieldDefs.Add(ADOTable1.FieldList.Fields[j].FieldName, ftInteger, ADOTable1.FieldList.Fields[j].Size, FALSE);
ftSmallint: b:=true;
ftCurrency: b:=true;
ftAutoInc: ClientDataSet.FieldDefs.Add(ADOTable1.FieldList.Fields[j].FieldName, ftInteger, 0, FALSE);
ftWord: b:=true;
ftFloat: b:=true;
ftBoolean: b:=true;
ftBCD: b:=true;
ftTime: b:=true;
ftDate: b:=true;
ftDateTime: b:=true;
ftBytes: b:=true;
ftVarBytes: b:=true;
ftBlob: b:=true;
ftMemo: b:=true;
ftGraphic: b:=true;
ftFmtMemo: b:=true;
ftParadoxOle: b:=true;
ftDBaseOle: b:=true;
ftTypedBinary:b:=true;
ftCursor: b:=true;
ftFixedChar: b:=true;
ftLargeint: b:=true;
ftADT: b:=true;
ftArray: b:=true;
ftReference: b:=true;
ftDataSet: b:=true;
ftOraBlob: b:=true;
ftOraClob: b:=true;
ftVariant: b:=true;
ftInterface: b:=true;
ftIDispatch: b:=true;
ftGuid: b:=true;
ftTimeStamp: b:=true;
ftFMTBcd: b:=true;
else
Begin
b:=false;
End;
end;
end;
// Dataset aktvieren
ClientDataSet.CreateDataset;
ClientDataSet.Open;
ClientDataSet.LogChanges:=false;
ADOTable1.First;
while not ADOTable1.eof do
begin
ClientDataSet.Append;
For j:=0 to ADOTable1.FieldList.count-1 do //ADOTable1.FieldList.Fields[j].FieldName
begin
ClientDataSet.FieldByName(ADOTable1.FieldList.Fields[j].FieldName).AsVariant := ADOTable1.FieldValues[ADOTable1.FieldList.Fields[j].FieldName];
end;
ADOTable1.next;
end;
ClientDataSet.SaveToFile('d:\Transfer.xml');
ClientDataSet.Close;
ClientDataSet.Free;
ADOTable1.First;
end;