Replace Text In XML Using Batch File

December 27, 2011 at 22:33:30
Specs: Windows 7
Here is my XML file. i want to set <Set Browser=' '/> to <Set Browser='firefox'/> though a batch file. And if it is already set then over right it. Please Help!!

<Set FrameworkPath='D:\projects\iLeap20'/>
<Set ApplicationURL=''/>
<Set TestDataFormat='' />
<Set TestData='Selenium\Test\TestData\TestData.xml'/>
<Set Browser=' '/>
<Set SeleniumIDE='no'/>
<Set Iteration='All'/>
<set executionSpeed='2000' />
<Set SMSNotification='01204092200'/>
<Set EMailNotification=''/>
<Set ErrorSnapshot='YES'/>
<Set ResultPath='Selenium\Test\Results/'/>
<Set ExcelPath='Selenium\Test\TestCase/'/>
<Set DataBase='NO'/>
<Set RunRecoveryScenario='YES'/>
<Set w3afFile = 'ThirdPartyLibs/w3af/securityScript.w3af'/>
<Set batchFileName='Selenium/Utility/Security/SecurityTesting.bat'/>
<Set w3afLocation='ThirdPartyLibs/w3af'/>
<Set project='intellicus' />
<Set testplan='intellicus test plan' />
<Set autoGenerateSuite='yes' />
<Set TCMTool='Testlink' />
<Set build='Build1.1' />
<Set testSuite='Regression' />
<Set autoGeneratemodulesuite='All' />
<Set DBServer='localhost' />
<Set Port='' />
<Set DBName='testlink' />
<Set user='root' />
<Set password='root' />
<Set generateSuiteBatch="D:\projects\iLeap20\Selenium\Utility\generate_suite.bat" />
<Set IESuiteBatch="D:\projects\iLeap20\Selenium\Utility\IE_ileap.bat" />
<Set FFSuiteBatch="D:\projects\iLeap20\Selenium\Utility\firefox_ileap.bat" />
<Set SafariSuiteBatch="D:\projects\iLeap20\Selenium\Utility\safari_ileap.bat" />
<Set ChromeSuiteBatch="D:\projects\iLeap20\Selenium\Utility\chrome_ileap.bat" />
<Set resultUpdateBatch="D:\projects\iLeap20\Selenium\Utility\TCM_result-update.bat" />
<Set resultDisplayBatch="D:\projects\iLeap20\Selenium\Utility\createResults.bat" />
<set includeFilePath="Selenium\Core\IleapLibs\FL_TestData.js,Selenium\Core\IleapLibs\FL_ConfigSettings.js,Selenium\Core\AppLibs\FL_App.js,Selenium\Core\IleapLibs\FL_Common2All.js" />

See More: Replace Text In XML Using Batch File

Report •

December 27, 2011 at 23:50:04
Please test this script:

@echo off>new.xml

for /f "tokens=*" %%1 in (old.xml) do (
    set line=%%1
    if /i "%line:~5,8%" equ "browser=" (echo ^<Set Browser='firefox'/^> >> new.xml
       ) else (
         echo %%1>>new.xml

Please come back & tell us if your problem is resolved.

Report •

December 28, 2011 at 01:13:27
No this code does not resolves my problem. Also I want my new xml file to be of the same name ie. config.xml . The batch file code is below:

@echo off>config1.xml

for /f "tokens=*" %%1 in (config.xml) do (
set line=%%1
if /i "%line:~5,8%" equ "browser=" (echo ^<Set Browser='firefox'/^> >> config1.xml
) else (
echo %%1>>config.xml
@echo Converting config.xml to js...
cd D:\Projects\iLeap20\Selenium\Utility
java ConvertXMLTOJS

@echo Converting object repository to js...
java createJSfromXML

@echo Checking for Excel test data
@echo Converting Excel test data to js
cd XLSX_To_JS_Converter
javac -Djava.ext.dirs="D:\Projects\iLeap20\Selenium\Utility\XLSX_To_JS_Converter"
java -Djava.ext.dirs="D:\Projects\iLeap20\Selenium\Utility\XLSX_To_JS_Converter" XLSXToJSConverter D:\Projects\iLeap20\Selenium

C:\wamp\bin\php\php5.3.8\php.exe -f D:\Projects\iLeap20\Selenium\Utility\dynamicFileGeneration.php
@echo Loading all files, Please wait...

cd D:\Projects\iLeap20\Selenium\Utility\SeleniumServer\selenium-server-1.0.3
java -Xdebug -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y -jar selenium-server.jar -htmlSuite "*chrome" "" "D:\Projects\iLeap20\Selenium\Test\Scripts\Regression_suite.html" "D:\Projects\iLeap20\Selenium\Test\Results\Results.html" -userExtensions D:\Projects\iLeap20\Selenium\Core\IleapLibs\user-extensions.js

Report •

December 28, 2011 at 09:58:53
for /f "tokens=*" %%1 in (config.xml) do (
set line=%%1
if /i "%line:~5,8%" equ "browser=" (echo ^<Set Browser='firefox'/^> >> config1.xml 
) else (
echo %%1>>config.xml 

Your amended script will not work because you write the amended line to Config1.xml the rest of the file you append to the existing Config.xml file.

You must write the entire output to a new file then when you are satisfied with the result delete (or preferably rename for backup) the existing Config.xml file then rename the new file to Config.xml.

I suggest that you test only the script to update the file before prepending it to your existing script.

Please come back & tell us if your problem is resolved.

Report •

Related Solutions

Ask Question