I have an XML file and I have a batch file to search for a specific string within that file, replace it with a string defined by the user and then output it to a new XML file:
@echo off > entities_1.xml
setLocal EnableDelayedExpansion
if exist entities_1.xml del entities_1.xml
set /p name= What is the new space NAME?
for /f "tokens=* delims= " %%G in (entities.xml) do (
set str=%%G
set str=!str:[Test Space]=[%name%]!
echo !str! >> entities_1.xml
)
This works and any instances of [Test Space] are replaced with the value defined by the user.
My issue, however, is that the batch file is ALSO stripping out instances of exclamation (!) marks. So for example in the XML there are lines similar to this:
<property name="title"><![CDATA[TEST2]]></property>
When the batch script is run, it is replacing the above with:
<property name="title"><[CDATA[TEST2]]></property>
I.e. stripping out the !.
Where am I going wrong? Any ideas?