2

I have to write a config file in the post section of installation and read from the config file if older version of the product exists.

config file is XML Configuration File (.config) config file will have so many entries like

<name>
   abcd
</name>
<company>
    xyz
</company>
<choise>
   choise1
</choise>

How to read only choise tag's text and overwrite only choise tag's text.

1
  • Above entries of config file had some formatting problem so please find the below comment for it - <name>abcd</name> <company>xyz</company> <choise>choise1</choise>
    – user1234
    Jan 6, 2012 at 8:53

1 Answer 1

2

NSIS has a total of 4 XML plug-ins to choose from; NsisXML (by Wizou), XML plug-in, NsisXML (by Joel) and NsXML

Using NsisXML (by Wizou):

Outfile "$%temp%\NSISTest.exe"
RequestExecutionLevel user
Installdir "$Temp"
Showinstdetails show
!include LogicLib.nsh
Page InstFiles

!define XMLFILE "$instdir\myxml.xml"

Section
StrCpy $9 "Did not exist"
nsisXML::create
nsisXML::load "${XMLFILE}"
${If} $0 = 0
    ;build a new basic XML file:
    nsisXML::create
    nsisXML::createProcessingInstruction "xml" 'version="1.0" encoding="UTF-8" standalone="yes"'
    nsisXML::appendChild
    nsisXML::release $2
${EndIf}
nsisXML::select '/choise'
${If} $2 = 0
    StrCpy $1 $0
    nsisXML::createElement "choise"
    nsisXML::appendChild
${Else}
    nsisXML::getText
    StrCpy $9 $3
${EndIf}
DetailPrint "Old value: $9"
System::Call 'kernel32::GetTickCount()i.r5' ;Get some "random" value to save
nsisXML::setText "$5"
nsisXML::release $2
nsisXML::save "${XMLFILE}"
nsisXML::release $0
DetailPrint "Saved new value: $5"
SectionEnd

On first run I get:

Old value: Did not exist
Saved new value: 709289703
Completed

and on the second run I got:

Old value: 709289703
Saved new value: 709308687
Completed
2
  • 1
    which plugin is the most recommended one ? Jul 15, 2012 at 8:38
  • 1
    @lysergic-acid: You should use the one that best fits your needs (I don't use any of them so I can't really tell you which is best)
    – Anders
    Jul 16, 2012 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.