Kylix
Tips

NEW TIPS
Database (98)
Files (1187)
Forms (125)
Graphic (126)
IDE (30)
Indy (13)
Internet / LAN (146)
IntraWeb (12)
Math (84)
Misc (137)
Multimedia (56)
Objects/
ActiveX (64)

OpenTools API (14)
Printing (47)
Strings (94)
System (275)
VCL (246)

Search Tip
Top15
Add new Tip

Forum

...convert a ADO Recordset to XML and the reverse way?
Author: Dmitry Lifatov
Homepage: http://www.bmaster.ru/ldm/
[ Print tip ]    

Tip Rating (11):  
     



unit ADOXMLUnit;

interface

uses
  
Classes, ADOInt;

function RecordsetToXML(const Recordset: _Recordset): string;
function RecordsetFromXML(const XML: string): _Recordset;

implementation

uses
  
ComObj;

{
  Example:
  ...
    Memo1.Lines.Text:=RecordsetToXML(ADOQuery1.Recordset);
  ...
}
function RecordsetToXML(const Recordset: _Recordset): string;
var 
  
RS: Variant;
  Stream: TStringStream;
begin
  
Result := '';
  if Recordset = nil then Exit;
  Stream := TStringStream.Create('');
  try
    
RS := CreateOleObject('ADODB.Recordset');
    RS := Recordset;
    RS.Save(TStreamAdapter.Create(stream) as IUnknown, adPersistXML);
    Stream.Position := 0;
    Result := Stream.DataString;
  finally
    
Stream.Free;
  end;
end;

{
  Example:
  ...
    ADOQuery1.Recordset:=RecordsetFromXML(Memo1.Lines.Text);
  ...
}

function RecordsetFromXML(const XML: string): _Recordset;
var 
  
RS: Variant;
  Stream: TStringStream;
begin
  
Result := nil;
  if XML = '' then Exit;
  try
    
Stream := TStringStream.Create(XML);
    Stream.Position := 0;
    RS := CreateOleObject('ADODB.Recordset');
    RS.Open(TStreamAdapter.Create(Stream) as IUnknown);
    Result := IUnknown(RS) as _Recordset;
  finally
    
Stream.Free;
  end;
end;

end.

Rate this tip:

poor
very good


Copyright  Torry's Delphi Pages Torry's Delphi Pages Maintained by Simon Grossenbacher Notes? Comments? Feel free to send... Copyright 1996-2001