Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2554
  • Last Modified:

Load XML Data into DATASET - my XML data is in a MEMO and I do not want any Files on Disk

I have Data in a XML File and I want to Populate a DATASET with the DATA,

I have tried a ClientDataSet with a .XTR File and it works,

But I do not WANT Any Files on DISK that I have to ship with my Application, nor do I want to CREATE
Temp Files.

The Perfect solution would be where I could just do this

MyDataSet.LoadXML(text);

Or any Function like XML2DS(xmlString,DataSet)

0
crestty
Asked:
crestty
  • 3
  • 2
1 Solution
 
MamouriCommented:

var
  AStream: TMemoryStream;
begin
  AStream := TMemoryStream.Create;
  try
    Memo1.Lines.SaveToStream(AStream);
    AStream.Position := 0;
    ClientDataSet1.LoadFromStream(AStream);
  finally
    AStream.Free;
  end;

Open in new window

0
 
cresttyAuthor Commented:
Mamouri,

as far as I know, ClientDataSet only accepts XML int its own format.

I have a STANDARD XML File, so the way to do it is to use a XMLTransformPRovider,

But his does not work since it seems that the only way to load the Transform File is from DISK.


I have also tried this Way:

But this also fails with an ERROR : XML not in correct Format;
So it seems that my XML is nowhere to be supported, yet it is standard XML.



{
  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;

Open in new window

0
 
MamouriCommented:
Hi

TXMLTransformat component provide property TransformationFile and TransformationDocument. It's possible to use TransformationDocument to feeding tranformation xml to component.
var
  TransformationXML: TXMLDocument;
begin
  TransformationXML := TXMLDocument.Create(Self);
  TransformationXML.LoadFromStream(AStream);
  XMLTransform1.TransformationDocument := TransformationXML.DOMDocument;

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
cresttyAuthor Commented:
Thank you. I will need to test it though.
0
 
cresttyAuthor Commented:
I used the Microsoft COM OLE Object Instead, and PARSED the XML Doc ( cycle Nodes );

While cycling the XML, I inserted the data into a Memory Dataset.
0
 
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now