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.