在Delphi中生成XML时如何编写XML? [英] How to write XML while it is beeing generated in Delphi?

查看:97
本文介绍了在Delphi中生成XML时如何编写XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Delphi中使用 TXMLDocument 生成XML文件。构建XML之后,我调用 SaveToStream 。因为建立XML文件需要很长时间,所以我需要一种解决方案来在流生成时写入流。

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?

推荐答案

使用TXMLDocument是不可能的。您将不得不找到满足您需求的另一个框架
,或者只是手动将其写入流中,例如:

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;

这篇关于在Delphi中生成XML时如何编写XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆