Edit XML File Issue

Got a problem you cannot solve? Try here.
SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Edit XML File Issue

Postby SebSpiers » Wed Jan 04, 2017 11:24 am

I'm trying to use the Edit XML File feature to edit one line within an XML file.

However I believe I'm having problems because the line I am trying to edit is an <add> function and not a standard attribute, eg;

Code: Select all

    <add key="RunAsService" value="False" />

I am specifying the correct Element Path "configuration\appSettings\" however I am unable to change the line.

Any ideas on this? I am trying to change this line to be value="True".

Any help is gratefully received.
I'm not a developer, I just want to install things...

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Edit XML File Issue

Postby FrancescoT » Wed Jan 04, 2017 12:20 pm

Dear SebSpiers,

please verify if the following links can be helpful (this first one also includes a small sample).

https://www.installaware.com/forums/viewtopic.php?f=2&t=10051&hilit=UseAgent
https://www.installaware.com/forums/viewtopic.php?f=2&t=10162&p=39933&hilit=Edit+xml#p38333

Hope this helps you.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE

SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Re: Edit XML File Issue

Postby SebSpiers » Thu Jan 05, 2017 7:04 am

I've looked at these threads but they don't really answer my question, either that or I don't understand.

This is the configuration I have:
Image

I am trying to edit this:

Code: Select all

<configuration>
  <appSettings>
      <add key="RunAsService" value="False"/>
      <add key="###Folder" value="C:\### Service\"/>
      <add key="SomethingElse" value="Whatever"/>
  </appSettings>
</configuration>


The file is modified and blank lines are added (not sure why) but the record is not updated with the new value.

Where am I going wrong?
I'm not a developer, I just want to install things...

SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Re: Edit XML File Issue

Postby SebSpiers » Thu Jan 05, 2017 11:12 am

I have found a work around which is to do this:

Code: Select all

Set Variable FILECONTENT to
Set Variable EOF to FALSE
while Variable EOF Equals FALSE loop
  Read from Text File C:\Program Files (x86)\XXXXXXXXXX\XXXXXXXXXX\XXXXXXXXXX.exe.config into Variable FILECONTENT (get EOF into EOF)
  Replace <add key="XXXFolder" value="C:\XXXXXXXXXX Service\"/> with <add key="XXXFolder" value="C:\Testing\"/> in variable FILECONTENT
  Write into Text File C:\Program Files (x86)\XXXXXXXXXX\XXXXXXXXXX\XXXXXXXXXX.exe.config.new from Value $FILECONTENT$ (at end of file)
wend
Run Program c:\Windows\System32\cmd.exe /c del "C:\Program Files (x86)\XXXXXXXXXX\XXXXXXXXXX\XXXXXXXXXX.exe.config" && copy "C:\Program Files (x86)\XXXXXXXXXX\XXXXXXXXXX\XXXXXXXXXX.exe.config.new" "C:\Program Files (x86)\XXXXXXXXXX\XXXXXXXXXX\XXXXXXXXXX.exe.config" && del "C:\Program Files (x86)\XXXXXXXXXX\XXXXXXXXXX\XXXXXXXXXX.exe.config.new" (WAIT)

I can of course change multiple lines within the same loop, but I don't feel that this is a good solution, it would be nice if the function within the application worked (or was easy to understand and/or get working).
I'm not a developer, I just want to install things...

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Edit XML File Issue

Postby FrancescoT » Thu Jan 05, 2017 1:33 pm

Dear SebSpiers,

unfortunately and because you want to update a not standard attribute, the only approach is the one you used.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE

SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Re: Edit XML File Issue

Postby SebSpiers » Fri Jan 06, 2017 3:46 am

FrancescoT wrote:unfortunately and because you want to update a not standard attribute, the only approach is the one you used.

You say this is "non standard" however this is a very common thing in XML config files for .Net applications?!?!!?
I'm not a developer, I just want to install things...

SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Re: Edit XML File Issue

Postby SebSpiers » Fri Jan 06, 2017 4:43 am

Also, the issue with the is that it will only work if the XML content is the initial value being looked for in the replace statements, if it has been changed previously the line will not be updated.

Any ideas on how I can get around that? a nested if statement within the loop with a contains checking the key name?! #urrrrrrrgh

Then how would I replace the entire line? :roll: :roll: :roll: :roll: :roll: :roll:
I'm not a developer, I just want to install things...


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 27 guests