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.