Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-21
7
Medium Priority
?
2,507 Views
Last Modified: 2013-11-23
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
Comment
Question by:crestty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 3

Expert Comment

by:Mamouri
ID: 21837913

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
 

Author Comment

by:crestty
ID: 21838009
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
 
LVL 3

Expert Comment

by:Mamouri
ID: 21855750
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:crestty
ID: 21856999
Thank you. I will need to test it though.
0
 

Author Comment

by:crestty
ID: 22086553
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 22859988
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question