2

I have a config file generated by VS:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <applicationSettings>
    <FMR.OrdersRouter.Service.Properties.Settings>
      <setting name="UseSQL" serializeAs="String">
        <value>True</value>
      </setting>
      <setting name="MaxNumOfConnectionsPerUser" serializeAs="String">
        <value>10</value>
      </setting>
      <setting name="DataPath" serializeAs="String">
        <value>C:\Program Files\Common Files\OrdersRouter</value>
      </setting>
      <setting name="CreditChecks" serializeAs="Xml">
        <value>
          <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <string>MAXMOFMARGIN:False</string>
            <string>BRSMAXASHRAI:True</string>
            <string>ADDCASH:False</string>
            <string>BUYPOWER:True</string>
          </ArrayOfString>
        </value>
      </setting>
      <setting name="InternalOrdersRouterServerIP" serializeAs="String">
        <value>172.25.2.186</value>
      </setting>
    </FMR.OrdersRouter.Service.Properties.Settings>
  </applicationSettings>
</configuration>

and I want to get a specific string from ArrayOfString. I need to get the value True/False after the "MAXMOFMARGIN:" or "BRSMAXASHRAI:" or "ADDCASH:" or "BUYPOWER:"

I tried this:

substring-after(/configuration/applicationSettings/FMR.OrdersRouter.Service.Properties.Settings/setting[@name="CreditChecks"]/value/ArrayOfString/string, 'BUYPOWER:')

But it works only for the first string in the string array.

Any suggestions?

har07
  • 88,338
  • 12
  • 84
  • 137
  • Do you mean your XPath only works if the target `` is the first child element of `` (so in the above example, it only works to find `MAXMOFMARGIN:`) ? – har07 Mar 30 '16 at 05:58
  • Yes. This is exactly what I mean. I think it's because of the new line between every child string the path returns for the first argument of the substring-after – user2787787 Mar 30 '16 at 12:55

1 Answers1

1

substring-after() expects a singleton argument, so when your argument expression returns multiple values, only the first value would be considered. Assuming that string values are always unique within a given ArrayOfString, then you can do this way (path simplified just to give an easily readable example) :

substring-after(//ArrayOfString/string[contains(.,'BUYPOWER:')], 'BUYPOWER:')

The XPath passes as first argument of substring-after() the string element that contains text 'BUYPOWER:'.

har07
  • 88,338
  • 12
  • 84
  • 137
  • NICE. It works :-) Thanks Now I want to use on my nsis scrip file. I'm also using the NsisXML plug-in (by Wizou). So how do I get returned value of substring-after() into a var ? – user2787787 Mar 30 '16 at 15:56
  • @user2787787 unfortunately, I know nothing about NsisXML – har07 Mar 31 '16 at 04:03