XML换行符号将替换为回车符

时间:2013-06-19 12:25:41

标签: xml delphi

我尝试加载XML文档并保存完整的副本。问题是所有换行符号(#10,十六进制0A)都用回车代替。 (#13#10,hex 0D0A)

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Information -->
<AddInsList>
  <AddInItem ID="name1">
    <Title DefaultText="Some text">
      <tag1><![CDATA[Some text]]></tag1>
    </Title>
    <Description DefaultText="some informations">
      <tag1><![CDATA[**Some text with line feed symbols 0A**]]></tag1>
    </Description>
  </AddInItem>
</AddInsList>

我的代码:

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, XMLIntf, XMLDoc, ActiveX, xmldom, StdCtrls, ComCtrls;

var
  Doc : IXMLDocument;

Begin
  Doc:=NewXMLDocument;

  //Prevent to change white spaces to tabulators
  Doc.ParseOptions := Doc.ParseOptions+[poValidateOnParse]+[poPreserveWhiteSpace];

  Doc.LoadFromFile('C:\test.xml');
  Doc.SaveToFile('C:\exact.xml');
End;

1 个答案:

答案 0 :(得分:0)

XML解析规范化换行符; XML序列化负责决定是否将它们转换回CRLF格式。见http://www.w3.org/TR/REC-xml/#sec-line-ends