I'm trying to create a batch file which reads 3 pair of identical XML files stored in two different locations and compares whether their build versions are same or not using different tags like build tag & minor tag in the xml files.
I have 3 XML files, master.xml,TGDD.xml and TMasterData.xml.I have stored these 3 xml files in 2 different locations and want to check whether their versions are same or not in these two locations.
Batch code is..
@echo off
setlocal enableextensions disabledelayedexpansion
set "build="
set "build1="
set "gddbuild="
set "gddbuild1="
set "tbuild="
set "tbuild1="
set "ans=Master_Data version same"
set "wrong=Master_Data version not same"
set "ans1=TGDD version same"
set "wrong1=TGDD version not same"
set "ans2=TMasterData version same"
set "wrong2=TMasterData version not same"
for /f "tokens=3 delims=<>" %%a in ('
2^>nul type "C:\Users\Lucy\Desktop\piller-uniblock\master.xml"
"C:\piller-uniblock\master.xml"
^| find /i "<Build>"
') do if not defined build ( set "build=%%a" ) else ( set "build1=%%a" )
IF "%build%"=="%build1%" ( echo %ans% ) else echo %wrong%
for /f "tokens=3 delims=<>" %%b in ('
2^>nul type "C:\Users\Lucy\Desktop\piller-uniblock\TGDD.xml"
"C:\piller-uniblock\TGDD.xml"
^| find /i "<Minor>"
') do if not defined gddbuild ( set "gddbuild=%%b" ) else ( set "gddbuild1=%%b" )
IF "%gddbuild%"=="%gddbuild1%" ( echo %ans1% ) else echo %wrong1%
for /f "tokens=3 delims=<>" %%c in ('
2^>nul type "C:\Users\Lucy\Desktop\piller-uniblock\TMasterData.xml"
"C:\piller-uniblock\TMasterData.xml"
^| find /i "<Build>"
') do if not defined tbuild ( set "tbuild=%%c" ) else ( set "tbuild1=%%c" )
IF "%tbuild%"=="%tbuild1%" ( echo %ans2% ) else echo %wrong2%
Even though the above code is running properly in the command prompt, I can't seem to understand how to make the above code more effcient i.e without using 3 for loops.Please Help...
The code for the 3 XML files are...
master.xml
<?xml version="1.0" encoding="UTF-8"?>
<CDMDataXML xmlns="http://ift.tt/1sXyXV0" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="http://ift.tt/1sXyXV0 CDMLoaderXMLSchema.xsd">
<CDMDataVersion>
<Major>1</Major>
<Minor>0</Minor>
<Build>50</Build>
<Delimiter>.</Delimiter>
</CDMDataVersion>
TGDD.xml
<?xml version="1.0" encoding="utf-8"?>
<TrellisGdd xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY">
<TrellisVersion>
<VersionId>1</VersionId>
<Major>3</Major>
<Delimiter>.</Delimiter>
<Minor>32</Minor>
<LastDictionaryEntry>3806</LastDictionaryEntry>
</TrellisVersion>
TMasterData.xml
<?xml version="1.0" encoding="UTF-8"?>
<CDMDataXML xmlns="http://ift.tt/1sXyXV0" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="http://ift.tt/1sXyXV0 CDMLoaderXMLSchema.xsd">
<CDMDataVersion>
<Major>3</Major>
<Minor>0</Minor>
<Build>15</Build>
<Delimiter>.</Delimiter>
</CDMDataVersion>
No comments:
Post a Comment