Page 1 of 1
Edit XML File Issue
Posted: Wed Jan 04, 2017 11:24 am
by SebSpiers
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.
Re: Edit XML File Issue
Posted: Wed Jan 04, 2017 12:20 pm
by FrancescoT
Dear SebSpiers,
please verify if the following links can be helpful (this first one also includes a small sample).
viewtopic.php?f=2&t=10051&hilit=UseAgent
viewtopic.php?f=2&t=10162&p=39933&hilit=Edit+xml#p38333
Hope this helps you.
Regards
Re: Edit XML File Issue
Posted: Thu Jan 05, 2017 7:04 am
by SebSpiers
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:
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?
Re: Edit XML File Issue
Posted: Thu Jan 05, 2017 11:12 am
by SebSpiers
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).
Re: Edit XML File Issue
Posted: Thu Jan 05, 2017 1:33 pm
by FrancescoT
Dear SebSpiers,
unfortunately and because you want to update a not standard attribute, the only approach is the one you used.
Regards
Re: Edit XML File Issue
Posted: Fri Jan 06, 2017 3:46 am
by SebSpiers
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?!?!!?
Re: Edit XML File Issue
Posted: Fri Jan 06, 2017 4:43 am
by SebSpiers