unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    XMLDocument1: TXMLDocument;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//读取或设置 xml 的编码与版本号
procedure TForm1.FormCreate(Sender: TObject);
begin
  XMLDocument1.LoadFromFile('c:\temp\test.xml');
  ShowMessage(XMLDocument1.Version);  {1.0}
  ShowMessage(XMLDocument1.Encoding); {gb2312}

  {另外, 这两个属性都是可写的, 譬如:}
  XMLDocument1.Encoding := 'UTF-8';

  Memo1.Lines := XMLDocument1.XML; {这时会显示乱码}
end;

end.

posted on 2008-01-03 18:13  万一  阅读(6603)  评论(0编辑  收藏  举报