Q
qianwt
Unregistered / Unconfirmed
GUEST, unregistred user!
怎么解决Delphi中XML的中文问题?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XMLDoc, XMLIntf;
type
TfrmMain = class(TForm)
Memo: TMemo;
btnLoadXMLFile: TButton;
btnLoadXMLSTR: TButton;
OpenDialog: TOpenDialog;
btnMsg: TButton;
btnGetXMLDOM: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnLoadXMLFileClick(Sender: TObject);
procedure btnLoadXMLSTRClick(Sender: TObject);
procedure btnGetXMLDOMClick(Sender: TObject);
procedure btnMsgClick(Sender: TObject);
private
{ Private declarations }
XMLDOM: TXMLDocument;
IXMLDOM: IXMLDocument;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
XMLDOM := TXMLDocument.Create(Self);
//XMLDOM.Encoding := 'UTF-8';
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
XMLDOM.Free;
end;
procedure TfrmMain.btnLoadXMLFileClick(Sender: TObject);
begin
if OpenDialog.Execute and FileExists(OpenDialog.FileName) then
begin
//XMLDOM.Encoding := 'UTF-8';
XMLDOM.LoadFromFile(OpenDialog.FileName);
//XMLDOM.Encoding := 'UTF-8';
XMLDOM.GetInterface(IXMLDocument, IXMLDOM);
end;
end;
procedure TfrmMain.btnLoadXMLSTRClick(Sender: TObject);
begin
//XMLDOM.Encoding := 'UTF-8';
XMLDOM.LoadFromXML(Memo.Text);
//XMLDOM.Encoding := 'UTF-8';
end;
procedure TfrmMain.btnGetXMLDOMClick(Sender: TObject);
begin
XMLDOM.GetInterface(IXMLDocument, IXMLDOM);
end;
procedure TfrmMain.btnMsgClick(Sender: TObject);
begin
ShowMessage(IntToStr(IXMLDOM.ChildNodes[0].ChildNodes.Count));
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XMLDoc, XMLIntf;
type
TfrmMain = class(TForm)
Memo: TMemo;
btnLoadXMLFile: TButton;
btnLoadXMLSTR: TButton;
OpenDialog: TOpenDialog;
btnMsg: TButton;
btnGetXMLDOM: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnLoadXMLFileClick(Sender: TObject);
procedure btnLoadXMLSTRClick(Sender: TObject);
procedure btnGetXMLDOMClick(Sender: TObject);
procedure btnMsgClick(Sender: TObject);
private
{ Private declarations }
XMLDOM: TXMLDocument;
IXMLDOM: IXMLDocument;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
XMLDOM := TXMLDocument.Create(Self);
//XMLDOM.Encoding := 'UTF-8';
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
XMLDOM.Free;
end;
procedure TfrmMain.btnLoadXMLFileClick(Sender: TObject);
begin
if OpenDialog.Execute and FileExists(OpenDialog.FileName) then
begin
//XMLDOM.Encoding := 'UTF-8';
XMLDOM.LoadFromFile(OpenDialog.FileName);
//XMLDOM.Encoding := 'UTF-8';
XMLDOM.GetInterface(IXMLDocument, IXMLDOM);
end;
end;
procedure TfrmMain.btnLoadXMLSTRClick(Sender: TObject);
begin
//XMLDOM.Encoding := 'UTF-8';
XMLDOM.LoadFromXML(Memo.Text);
//XMLDOM.Encoding := 'UTF-8';
end;
procedure TfrmMain.btnGetXMLDOMClick(Sender: TObject);
begin
XMLDOM.GetInterface(IXMLDocument, IXMLDOM);
end;
procedure TfrmMain.btnMsgClick(Sender: TObject);
begin
ShowMessage(IntToStr(IXMLDOM.ChildNodes[0].ChildNodes.Count));
end;
end.