Read XML attribute value in Inno Setup

66 Views Asked by At

Using How to read and write XML document node values in Inno Setup? I'm able to read values from XML file.

My file is not type XML but config (myApp.exe.config) with XML configuration:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="foo" type="bar">
      <section name="foo2" type="bar2" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
      <section name="foo3" type="bar3" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="foo, bar">
      <parameters>
        <parameter value="v12.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <clear />
    <add name="AppEntities" connectionString="NEED THIS VALUE" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>  
</configuration>

When using:

LoadValueFromXML(
  ExpandConstant('{app}\myApp.exe.config'),
  '//configuration/connectionStrings/add');

or

LoadValueFromXML(
  ExpandConstant('{app}\myApp.exe.config'),
  '//configuration/connectionStrings');

I'm still getting empty string. What am I doing wrong?

1

There are 1 best solutions below

1
Martin Prikryl On

See Extract value of attribute node via XPath.

So in your case, the XPath is:

/configuration/connectionStrings/add/@connectionString

(also note the single leading / - as <configuration> is the root tag)