BdLm
asked on
save and load msxml to Blob ...
now 2 function to load and store MSXM documents to a Blob ...
I'm in trouble using Streams
I'm in trouble using Streams
{**********************************************
* in:
*
* aTable [paradox table]
* aXMLField [fieldname]
* axmldoc MSXML IXMLDomDocument
*
* Support: http://www.experts-exchange.com/Programming/Languages/Pascal/Q_23022273.html
* still i do something wrong ....
**********************************************}
procedure SaveXMLDocToTable(aTable: TTable; aXMLField : TBlobField; aXMLdoc : IXMLDomDocument);
var ss : TStringStream;
begin
ss := TStringStream.Create(axmldoc.xml);
with aTable do
begin
Edit;
Try
aXMLField.SaveToStream(ss);
// use the ss
// XMLStr := ss.ReadString(ss.Size);
finally
ss.free
end;
Post;
end;
end;
{***********************************************
*
* reverse function of above
***********************************************}
procedure SaveTableToXMLDoc(aTable: TTable; aXMLField : TBlobField; var aXMLdoc : IXMLDomDocument);
var ss : TStringStream;
begin
ss := TStringStream.Create('');
with aTable do
begin
Edit;
Try
aXMLField.SaveToStream(ss);
aXMLdoc.loadXML(ss.ReadString(ss.Size));
finally
ss.free;
end;
Post;
end;
end;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
aXMLdoc : IXMLDomDocument does not have a SaveToStream(ss) methode, pls see
https://www.experts-exchange.com/questions/23022273/Delphi-save-MSXML-to-BLOB.html
https://www.experts-exchange.com/questions/23022273/Delphi-save-MSXML-to-BLOB.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@stevebay -> the first fct. now solved by myself, the second with your help
**********************************************
* in:
*
* aTable [paradox table]
* aXMLField [fieldname]
* axmldoc MSXML IXMLDomDocument
*
* Support: http://www.experts-exchange.com/Programming/Languages/Pascal/Q_23022273.html
* still i do something wrong ....
**********************************************}
procedure SaveXMLDocToTable(aTable: TTable; aXMLField : TBlobField; aXMLdoc : IXMLDomDocument);
var ss: TStringStream;
begin
with aTable do
begin
Edit;
try
ss:=TStringStream.Create(aXMLDoc.xml);
ss.position := 0;
aXMLField.LoadFromStream(ss);
finally
FreeAndNil(ss);
end;
Post;
end;
end;
{***********************************************
*
* reverse function of above
* pass first tests !
***********************************************}
procedure SaveTableToXMLDoc(aTable: TTable; aXMLField : TBlobField; var aXMLdoc : IXMLDomDocument);
var ss: TStringStream;
begin
ss:=TStringStream.Create('');
with aTable do
begin
try
aXMLField.SaveToStream(ss);
ss.position := 0; // << ALWAYS reset stream position before reading
aXMLdoc.loadXML(ss.ReadString(ss.Size));
finally
ss.free;
end;
end;
end;
keep create and free of object on same level
Otherwise you may have memory leaks
Otherwise you may have memory leaks
//ss:=TStringStream.Create('');
with aTable do // Level 1
begin
ss:=TStringStream.Create(''); // Level 2
try
aXMLField.SaveToStream(ss);
ss.position := 0; // << ALWAYS reset stream position before reading
aXMLdoc.loadXML(ss.ReadString(ss.Size));
finally
ss.free; // Level 2
end;
end; // Level 1
ASKER
good point, it is an important topic
would be nice if Borland can do this job for me with the next Delphi release ...
would be nice if Borland can do this job for me with the next Delphi release ...
ASKER
ss.ReadString need type TStringStream
but then ss := aTable.CreateBlobStream(aX