bsp; U_Id = ''id'';
U_Name = ''name'';
U_Sex = ''sex'';
U_Birth = ''birth'';
U_Tel = ''tel'';
U_Addr = ''addr'';
U_PostCode = ''postcode'';
U_Email = ''email'';
//创建一个空XML,如果这个Filename文件已经存在,则覆盖
procedure TXMLOption.CreateBlank(Filename: string);
begin
FActive:=false;
FFilename:='''';
try
FXMLDoc := CoDOMDocument.Create;
FXMLDoc.AppendChild(FXMLDoc.CreateProcessingInstruction(XMLTag, XMLPrologAttrs));
FXMLDoc.AppendChild(FXMLDoc.CreateComment(XMLComment));
FXMLDoc.AppendChild(FXMLDoc.CreateElement(UserWatcherTag));
FXMLDoc.AppendChild(FXMLDoc.CreateComment(XMLComment2+datetimetostr(now)));
FXMLDoc.save(Filename);
FFilename:=Filename;
FActive:=true;
except
FXMLDoc:=nil;
end;
end;
//打开一个存在的Filename XML文档
procedure TXMLOption.OpenXml(Filename: string);
begin
if not Assigned(FXMLDoc) then
begin
FXMLDoc := CoDOMDocument.Create;
if FXMLDoc.Load(Filename) then FActive:=true
else FActive:=false;
if FActive then FFilename:=Filename
else FFilename:='''';
end;
end;
//关闭一个打开的XML文档
procedure TXMLOption.CloseXml;
begin
if Assigned(FXMLDoc) then FXMLDoc:=nil;
FFilename:='''';
FActive:=false;
end;
procedure TXMLOption.AddSimpleElement(Parent: IXMLDOMElement; Field,Value: string);
var
Internal: IXMLDOMElement;
begin
Internal:=IXMLDOMElement(Parent.AppendChild(FXMLDoc.CreateElement(Field)));
Internal.AppendChild(FXMLDoc.CreateTextNode(Value));
end;
//填加一个节点到后面
procedure TXMLOption.AppendUser(muser:RecUser);
var
xuser:IXMLDOMElement;
xroot:IXMLDOMElement;
begin
if FActive then
begin
xroot:=FXMLDoc.documentElement;
xuser :=IXMLDOMElement(xroot.AppendChild(FXMLDoc.CreateElement(UsersTag)));
AddSimpleElement(xuser,U_Id,muser.U_Id);
AddSimpleElement(xuser,U_Name,muser.U_Name);
AddSimpleElement(xuser,U_Sex,muser.U_Sex);
AddSimpleElement(xuser,U_Birth,muser.U_Birth);
AddSimpleElement(xuser,U_Tel,muser.U_Tel);
AddSimpleElement(xuser,U_Addr,muser.U_Addr);
AddSimpleElement(xuser,U_PostCode,muser.U_PostCode);
AddSimpleElement(xuser,U_Email,muser.U_Email);
FXMLDoc.save(FFilename);