0

I am making some changes to an installer. The XML file needs some values changed while installation which is handled by Wix.

The config file has multiple nodes with the same name. example below.

<service>

<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>D:\tools\nginx-1.13.2\nginx.exe</executable>
<logpath>D:\tools\nginx-1.13.2\logs</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p</startargument>
<startargument>D:\tools\nginx-1.13.2</startargument>
<stopexecutable>D:\tools\nginx-1.13.2\nginx.exe</stopexecutable>
<stopargument>-p</stopargument>
<stopargument>D:\tools\nginx-1.13.2</stopargument>
<stopargument>-s</stopargument>
<stopargument>stop</stopargument></service>

From my understanding of Xpath I can use /service/startargument[2] to get the second node of the same name. The wix command below this is also what I have tried.

<util:XmlFile Id="NginxStartArgs" Action="setValue" ElementPath="/service/startargument[2]" File="[!nginxservice.xml]" Value="[NginxDir]" />

The Wix docs state

The XPath of the element to be modified. Note that this is a formatted field and therefore, square brackets in the XPath must be escaped. In addition, XPaths allow backslashes to be used to escape characters, so if you intend to include literal backslashes, you must escape them as well by doubling them in this attribute. The string is formatted by MSI first, and the result is consumed as the XPath.

I have also tried

<util:XmlFile Id="NginxStartArgs" Action="setValue" ElementPath="/service/startargument[\[]2[\]]" File="[!nginxservice.xml]" Value="[NginxDir]" />

but this will tried an find a node called /service/startargument[2] which of course isn't there.

Anyone experienced with Wix and XML that can lend a hand?

Chris Birch
  • 41
  • 2
  • 7
  • *this will tried an find a node called /service/startargument[2] which of course isn't there.* -- actually it **is** there. That path correctly selects the second `` element, see e.g. https://dotnetfiddle.net/Dd9nH0. See also [WIX XmlConfig VerifyPath escaping](https://stackoverflow.com/q/46832768/3744182) which suggests that your second attempt ought to work. – dbc Nov 25 '20 at 20:03
  • All I have right now is [a little sample here](https://github.com/glytzhkof/WiXUpdateXmlFile). – Stein Åsmul Nov 26 '20 at 02:44
  • Oddly the second example does build. But the install fails as it cant find node startargument[2]. I will check over what ive done and look at the examples. Thank you – Chris Birch Nov 27 '20 at 10:34

0 Answers0