Const
Xmlfilename = ' App. config ' ;
//-------------------------------------------------------------
VaR
Xmldoc, key1node: variant;
Xmlstring, path, key1value: string;
Begin
Try
Xmldoc: = Createoleobject ( ' Msxml2.domdocument. 4.0 ' );
Except
Raiseexception ( ' Please install MSXML first. ' # 13 # 13 ' (Error'' ' + Getexceptionmessage + ' ''Occurred) ' );
End ;
Xmldoc. async: = False;
Xmldoc. resolveexternals: = False;
Path: = Expandconstant ( ' {SRC }\ ' );
//*************** Create an XML file ***************
// Xmlstring: = ' <? XML version = ''1. 0 ''encoding = ''utf-8''?> ' +
// ' <Configuration> ' # 13 # 10 +
// ' <Deleetask> ' # 13 # 10 +
// ' <Add key = ''key1' value = ''value1 ''> </Add> ' # 13 # 10 +
// ' <! -- <Add key = ''key2' value = ''value2''> </Add> --> ' # 13 # 10 +
// ' </Appsettings> ' # 13 # 10 +
// ' </Configuration> ' ;
// Xmldoc. loadxml (xmlstring );
// Xmldoc. Save (Path + Xmlfilename );
//************** Load and read XML files ***************
Xmldoc. Load (Path + Xmlfilename );
If Xmldoc. parseerror. errorcode <> 0 Then
Raiseexception ( ' Error on line ' + Inttostr (xmldoc. parseerror. Line) + ' , Position ' + Inttostr (xmldoc. parseerror. linepos) + ' : ' + Xmldoc. parseerror. Reason );
Msgbox ( ' Loaded the XML file. ' , Mbinformation, mb_ OK );
{ Modify the XML document }
Rootnode: = Xmldoc. documentelement;
Appsetnode: = Rootnode. selectsinglenode ( ' Appsettings ' );
Key1node: = Deleetnode. selectsinglenode ( ' /Configuration/appsettings/Add [@ key = ''key1'] ' );
Key1value: = Key1node. Attributes. getnameditem ( ' Value ' ). Value;
Msgbox (key1value, mbinformation, mb_ OK );
// Rootnode. removechild (deleetnode );
Deleetnode. removechild (key1node );
Xmldoc. Save (Path + Xmlfilename );
Msgbox ( ' Saved the modified XML'' ' + Xmlfilename + ' ''. ' , Mbinformation, mb_ OK );
End ;