whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

38 Visitors Online


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

Tip Rating (24):  
     


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 © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners