operties(Element: IXMLDOMNode; PropPrefix: string);
var
Index: Integer;
begin
if (Element.NodeType = NODE_TEXT) or (Element.NodeType = NODE_CDATA_SECTION) then
Props.Add(Copy(PropPrefix, 2, Length(PropPrefix) - 1)+''=''+ Element.NodeValue)
else
for Index := 0 to Element.ChildNodes.Length - 1 do
LoadSubProperties(Element.ChildNodes[Index], PropPrefix + ''.'' + Element.NodeName);
end;
begin
XMLDoc := CoDOMDocument.Create;
Props.Clear;
try
if XMLDoc.Load(Filename) then
with XMLDoc.DocumentElement do
for i := 0 to ChildNodes.Length - 1 do
LoadSubProperties(ChildNodes[i], '''');
finally
XMLDoc := nil;
end;
end;
initialization
{ Initialise COM }
CoInitialize(nil);
finalization
{ Tidy up }
CoUninitialize();
end.
//调用XML读写
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw,XMLPurserUnit;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
FXMLpurser:TDOMXMLpurser;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FXMLpurser:=TDOMXMLpurser.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FXMLpurser.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
filename:string;
begin
memo1.Lines.Clear;
filename:=ExtractFilePath(application.ExeName)+''MailTemplate.xml'';
FXMLpurser.LoadPropertiesFromXML(filename,memo1.Lines);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
filename:string;
begin
memo1.Lines.Clear;
filename:=ExtractFilePath(application.ExeName)+''MailTemplate.xml'';
FXMLpurser.LoadFromXML(filename,memo1.Lines);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
FXMLpurser.SavePropertiesToXML(ExtractFilePath(application.ExeName)+''Ma