title: Batch file - code to edit a string between strings in a dtsconfig / xml file
body: <p>I have written a batch file to replace certain strings in a dtsConfig file.
  Now from what I can gather, batch cannot directly edit dtsconfig files so a workaround I'm using which works is 
  to convert the .dtsConfig files into .xml first, edit them, and convert them back. </p>
  
  <p>However I have a lot of .dtsconfig files with several different strings i want to change</p>
  
  <p>e.g. the string SERVER_NAME</p>
  
  <p><code>&lt;ConfiguredValue&gt; Data Source=SERVER_NAME;Integrated Security=True;&lt;/ConfiguredValue&gt;</code></p>
  
  <p>My code below is able to change the SERVER_NAME value but instead I would prefer to change the contents between
  Data Source=    and ;Integrated Security. so that I could do it for a lot of dtsConfig files that might have different server names</p>
  
  <p>Is this possible with batch?</p>
  
  <p>This is my code below:</p>
  
  <p><pre><code>
  @echo off > *.xml
  setLocal DisableDelayedExpansion</p>
  
  <p>:: make a copy of the .dtsConfig files
  set str="C:\dtsconfig\copyArea"</p>
  
  <p>:: Copy all dtsConfig files into the backup directory
  xcopy "*.dtsConfig" %str1% /E /I</p>
  
  <p>:: Rename all .dtsConfig files to .xml to enable batch to work with them
  ren *.dtsConfig *.xml</p>
  
  <p>:: set the new server name
  set dataSource=NEW_SERVER_NAME</p>
  
  <p>@echo off > ConfigFile.dtsConfig
  setLocal DisableDelayedExpansion</p>
  
  <p>if exist ConfigFile.dtsConfig del ConfigFile.dtsConfig</p>
  
  <p>for /f "tokens=* delims= " %%G in (ConfigFile.xml) do (
      set str=%%G</p>
  
  <code>setLocal EnableDelayedExpansion
  
  :: set the string "SERVER_NAME" to be the dataSource defined above
  set str=!str:SERVER_NAME=%dataSource%!
  
  :: generate a new dtsConfig file with the rename in place
  &gt;&gt; ConfigFile.dtsConfig echo(!str!
  endlocal) 
  </code></pre>
  
  <p></code></p>
  
  <p>Thank you.</p>