I generate a XML file using TXMLDocument
in Delphi. After the XML is build up, I call SaveToStream
. Because it takes a long time to build up the XML file, I need a solution to write to the stream while it is beeing generated. How can that be done?
Asked
Active
Viewed 516 times
2

Alois Heimer
- 1,772
- 1
- 18
- 40
-
possible duplicate of [Replacing TXMLDocument-DOM-based XML-generation with a solution that is able to write to a stream while the XML file is generated](http://stackoverflow.com/questions/18654127/replacing-txmldocument-dom-based-xml-generation-with-a-solution-that-is-able-to) – David Heffernan Sep 09 '13 at 08:55
-
1@DavidHeffernan Yes, the possible duplicate is a special case of that problem. But the question has been closed, because I asked for a library and the rewording of this question did not seem to be enough to resolve this. Therefore I thought I formulate another more common question, that is not conflicting with the rules. – Alois Heimer Sep 09 '13 at 09:09
-
Please put the re-wording in an edit to the old question. And then we can try to re-open it. – David Heffernan Sep 09 '13 at 09:10
-
@DavidHeffernan I have already reworded that question. But if I would ask in such a common way like in this question, the original sense of the question will be lost. – Alois Heimer Sep 09 '13 at 09:22
-
You might want to have a look at NativeXML or OmniXML – Glen Morse Sep 09 '13 at 09:42
-
@GlenMorse I have already looked at both, but could not find out, how they could resolve my problem. Do you have an example? All the examples I could find, seemed to be calling SaveTo... after the generation of the XML. – Alois Heimer Sep 09 '13 at 09:55
-
@GlenMorse Did you just copy the answer from the other question? – David Heffernan Sep 09 '13 at 10:16
-
@DavidHeffernan, no i did not read other question cause it was closed or so it seems.. I just know about those two cause i looked into useing them for an application. – Glen Morse Sep 09 '13 at 10:22
-
@GlenMorse Amazing coincidence then that the text was identical, even including the omission of the full stop. ;-) – David Heffernan Sep 09 '13 at 10:28
-
@DavidHeffernan heh thats awsome, I had to open the question link now and check for my self... anyhow alois, i am still looking ..kind of doing two things. – Glen Morse Sep 09 '13 at 10:31
-
What are you looking for here? A library to do this? Or are you going to code it yourself? Former is off topic, latter is too broad. Not trying to be unhelpful, just not quite sure how you are going to get help. – David Heffernan Sep 09 '13 at 20:04
-
@DavidHeffernan I cite: "Questions asking us to ... find a ... library are off-topic ... as they tend to attract opinionated answers ... Instead, describe the problem." My problem is described above. If it can be solved using TXMLDocument - fine. If it is best done using an external library - OK. I am asking for an example or for some pseudocode how to do it. I do not want to offend anyone, but how else should I ask? – Alois Heimer Sep 09 '13 at 21:45
-
1I suspect there is no such library for Delphi. So I think you may be out of luck. – David Heffernan Sep 09 '13 at 21:48
-
@DavidHeffernan I think this is valuable information, thank you. – Alois Heimer Sep 09 '13 at 22:00
-
@AloisHeimer stop it, your making his head grow bigger! – Glen Morse Sep 10 '13 at 10:55
1 Answers
1
It is not possible with TXMLDocument. You will have to find another framework that does what you need, or just write to the stream manually, eg:
procedure WriteToStream(Stream: TStream; const S: UTF8String);
begin
Stream.WriteBuffer(Pointer(S)^, Length(S));
end;
var
Stream: TStream;
begin
Stream := ...;
try
WriteToStream(Stream, '<?xml version="1.0" encoding="utf-8" ?>'#13);
WriteToStream(Stream, '<my_doc_element>');
WriteToStream(Stream, '<my_child_element>');
...
WriteToStream(Stream, '</my_child_element>');
WriteToStream(Stream, '</my_doc_element>');
finally
Strm.Free;
end;
end;

Glen Morse
- 2,437
- 8
- 51
- 102
-
+1 for the example code. Nevertheless I'll leave the question open, as this is no fully satisfactory answer to me. Yes I know, perhaps such an answer does not exist. – Alois Heimer Sep 10 '13 at 18:52
-
Not really, the direction is clear. But there is a [long way to go](http://www.docjar.com/html/api/org/apache/xml/serialize/XMLSerializer.java.html) from your sample code to generating more than a simplistic xml file. So yes, this is useful, but no, it is not an appropriate solution for me. – Alois Heimer Sep 11 '13 at 07:40