0

I have to replace an XML node attribute value using a batch file, XSLT and other methods are not an option.

Node attribute to find: add key="RemEnabled" value="true" />

To be replaced with: add key="RemEnabled" value="false" />

I am struggling with the fact there are quotes, what I have so far is:

echo off
setlocal enabledelayedexpansion
set txtfile=x.config
set newfile=xnew.config
if exist "%newfile%" del /f /q "%newfile%"
for /f "tokens=*" %%a in (%txtfile%) do (
set newline=%%a 
set newline=!newline:^"RemEnabled^" value=^"true^"=^"RemEnabled^" value=^"false^"!
echo !newline! >> %newfile%
)

Any help much appreciated

1 Answer 1

1

This uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

type file.xml|repl "(.*add key=\x22RemEnabled\x22 value=\x22)true(\x22 \/>.*)" "$1false$2" >file2.xml
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.