unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
XMLDocument1: TXMLDocument;
Memo1: TMemo; {Memo}
WebBrowser1: TWebBrowser; {WebBrowser}
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses ShellAPI; {为提供 ShellExecute 函数}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('c:\temp\test.xml');
end;
// xml 格式化输出, 通过 Memo 显示
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Text := FormatXMLData(XMLDocument1.XML.Text);
{TXMLDocument 所在的 XMLDoc 单元给我们提供了 xml 格式化函数 FormatXMLData}
end;
//先保存修改结果, 通过 WebBrowser 会有更好的显示效果
procedure TForm1.Button2Click(Sender: TObject);
begin
XMLDocument1.SaveToFile('c:\temp\test2.xml');
WebBrowser1.Navigate('c:\temp\test2.xml');
end;
//先保存, 然后用外部浏览器显示, 需要 uses ShellAPI 单元
procedure TForm1.Button3Click(Sender: TObject);
begin
XMLDocument1.SaveToFile('c:\temp\test2.xml');
ShellExecute(Handle, 'open', 'Explorer.exe', 'c:\temp\test2.xml', nil, SW_SHOWNORMAL);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
XMLDocument1: TXMLDocument;
Memo1: TMemo; {Memo}
WebBrowser1: TWebBrowser; {WebBrowser}
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses ShellAPI; {为提供 ShellExecute 函数}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('c:\temp\test.xml');
end;
// xml 格式化输出, 通过 Memo 显示
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Text := FormatXMLData(XMLDocument1.XML.Text);
{TXMLDocument 所在的 XMLDoc 单元给我们提供了 xml 格式化函数 FormatXMLData}
end;
//先保存修改结果, 通过 WebBrowser 会有更好的显示效果
procedure TForm1.Button2Click(Sender: TObject);
begin
XMLDocument1.SaveToFile('c:\temp\test2.xml');
WebBrowser1.Navigate('c:\temp\test2.xml');
end;
//先保存, 然后用外部浏览器显示, 需要 uses ShellAPI 单元
procedure TForm1.Button3Click(Sender: TObject);
begin
XMLDocument1.SaveToFile('c:\temp\test2.xml');
ShellExecute(Handle, 'open', 'Explorer.exe', 'c:\temp\test2.xml', nil, SW_SHOWNORMAL);
end;
end.
出处:http://www.cnblogs.com/del/archive/2008/01/07/1029029.html