Author: Jonas Bilinkevicius How to convert a ADO Recordset to XML and the reverse way Answer: 1 unit ADOXMLUnit; 2 3 interface 4 5 uses 6 Classes, ADOInt; 7 8 function RecordsetToXML(const Recordset: _Recordset): string; 9 function RecordsetFromXML(const XML: string): _Recordset; 10 11 implementation 12 13 uses 14 ComObj; 15 16 function RecordsetToXML(const Recordset: _Recordset): string; 17 var 18 RS: Variant; 19 Stream: TStringStream; 20 begin 21 Result := ''; 22 if Recordset = nil then 23 Exit; 24 Stream := TStringStream.Create(''); 25 try 26 RS := CreateOleObject('ADODB.Recordset'); 27 RS := Recordset; 28 RS.Save(TStreamAdapter.Create(stream) as IUnknown, adPersistXML); 29 Stream.Position := 0; 30 Result := Stream.DataString; 31 finally 32 Stream.Free; 33 end; 34 end; 35 36 function RecordsetFromXML(const XML: string): _Recordset; 37 var 38 RS: Variant; 39 Stream: TStringStream; 40 begin 41 Result := nil; 42 if XML = '' then 43 Exit; 44 try 45 Stream := TStringStream.Create(XML); 46 Stream.Position := 0; 47 RS := CreateOleObject('ADODB.Recordset'); 48 RS.Open(TStreamAdapter.Create(Stream) as IUnknown); 49 Result := IUnknown(RS) as _Recordset; 50 finally 51 Stream.Free; 52 end; 53 end; 54 55 end.