问题
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:
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
来源:https://stackoverflow.com/questions/8755393/how-to-write-or-read-from-xml-config-file-config