Inno Setup operation XML

Source: Internet
Author: User
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 ;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.