简体   繁体   中英

Read XML file inside JAR file using Windows Batch

I have a XML file TData.xml which has been stored at 2 different Locations.I want to see whether their versions are same or not by reading the build tags in each copy of that file. I'm able to read the copy stored in the 1st location but not the copy stored in the 2nd location as it has been stored inside an executable JAR file along with another xml file called as data.xml.

The batch code I used..

 @echo off
 fc D:\lucy\MasterData\TData.xml W:\MasterDataGDDFolders\Trellis_3.3_Higher\MasterData.jar\TData.xml /A > nul

if errorlevel 1 (
    echo.
    echo in SVN
    findstr "<Build>" D:\lucy\MasterData\TData.xml
    echo.
    echo  in DropBox
    findstr "<Build>" W:\MasterDataGDDFolders\Trellis_3.3_Higher\MasterData.jar\TData.xml
    echo.
    echo.
    echo TData files are different.
) else (
    echo.
    echo in SVN
    findstr "<Build>" D:\lucy\MasterData\TData.xml
    echo.
    echo  in DropBox
    findstr "<Build>" W:\MasterDataGDDFolders\Trellis_3.3_Higher\MasterData.jar\TData.xml
    echo.
    echo.
    echo TData files matches.

)

The contents of MasterData.jar are TData.xml & Data.xml

XML code for TData.xml

    <?xml version="1.0" encoding="UTF-8"?>
   <CDMDataVersion>
    <Major>3</Major>
    <Minor>0</Minor>
    <Build>19</Build>
    <Delimiter>.</Delimiter>
   </CDMDataVersion>

Out of the 2 xml files inside the jar file i want to read only TData.xml. Could you please tell me where I'm going wrong in the above code..

You can't access directly to the jar content through findstr command, at first you must unzip the jar and then access the content, if you have a 7-zip installed you can do the follow:

"%ProgramFiles%\\7-Zip\\7z.exe" x -y W:\\MasterDataGDDFolders\\Trellis_3.3_Higher\\MasterData.jar -oW:\\MasterDataGDDFolders\\Trellis_3.3_Higher\\MasterData

x is for extract. -y is to say yes to all prompts, and -o is to specify output directory note that there is no spaces between -o and the output: -oW:\\Master...

The you can access your jar files through the folder where you extract it's content. In combination with your findstr :

"%ProgramFiles%\7-Zip\7z.exe" x -y W:\MasterDataGDDFolders\Trellis_3.3_Higher\MasterData.jar -oW:\MasterDataGDDFolders\Trellis_3.3_Higher\MasterData
findstr "<Build>" W:\MasterDataGDDFolders\Trellis_3.3_Higher\MasterData\TData.xml 

Hope this helps,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM