I am days trying to change a value in an XML file I found some things and I was adapting but I still didn't have success I need to change the value of the TAG showLockNotifications from 0 to 1 but when running the script it changes all lines .
could someone help me?
<?xml version="1.0"?>
<useroptions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<useroption name="showLockNotifications" value="0" /> <-- ** I'd like to change only this value to 1**
<useroption name="showLowBatteryNotifications" value="1" />
<useroption name="showBacklightingAdjustments" value="1" />
<useroption name="automaticCheckForUpdates" value="1" />
<useroption name="collectAnonymousData" value="0" />
<useroption name="isAutoBackupEnabled" value="1" />
<useroption name="HideAnalytics" value="0" />
<useroption name="showFlowNotificationIcon" value="1" />
</useroptions>
I have tried this code but it replaces all lines in the file...
@echo off
setlocal EnableDelayedExpansion
set anotherVariable=1
(for /F "delims=" %%a in (options.xml) do (
set "line=%%a"
set "newLine=!line:name="showLockNotifications">=!"
if "!newLine!" neq "!line!" (
set "newLine= <useroption name="showLockNotifications" value="%anotherVariable%" />"
)
echo !newLine!
)) > newFile.xml
Output:
<?xml version="1.0"?>
<useroptions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<useroption name="showLockNotifications" value="1" />
<useroption name="showLockNotifications" value="1" />
<useroption name="showLockNotifications" value="1" />
<useroption name="showLockNotifications" value="1" />
<useroption name="showLockNotifications" value="1" />
<useroption name="showLockNotifications" value="1" />
<useroption name="showLockNotifications" value="1" />
<useroption name="showLockNotifications" value="1" />
</useroptions>