如何从批处理文件中的xml中获取属性值以创建运行文件的条件

问题描述 投票:0回答:1

如何使用批处理文件从xml文件(build.xml)中获取属性值并设置条件以确定是否运行xml文件?

我想从build.xml中获取以下值:

<property name="appbox1URL" value="http://10.111.111.111"/>
<property name="appbox2URL" value="http://10.222.222.222"/>
<property name="domainName" value="xxxG"/>

在我的批处理文件中,我想使用这些值来确定是否可以在运行该构建文件时进行调用。还有另一组值被接受以使条件成立,一个用于xxxG,另一个用于Stage。

批处理文件中的伪

If appbox1URL = "http://10.111.111.111" and appbox2URL = "http://10.222.222.222" and domainName = "xxxG"
OR 
If appbox1URL = "http://10.111.111.000" and appbox2URL = "http://10.222.222.000" and domainName = "Stage"
THEN
call ant -buildfile "D:\xxx\Trunk\build.xml"

这假设如何在批处理文件中编码?

directory of build.xml - "D:\xxx\Trunk\build.xml"
directory of batchfile.bat - "D:\xxx\Trunk\Batch\batchfile.bat"
xml batch-file
1个回答
0
投票

检查xpath.bat(它应该与以下脚本位于同一目录中):

:: Set relative path here if needed
set "xmlFile=D:\xxx\Trunk\build.xml"


for /f "usebackq delims=* tokens=" %%a in (`xpath.bat "%xmlFile%" "//property[@name='appbox1URL']/@value" `) do set "appbox1URL=%%a"

for /f "usebackq delims=* tokens=" %%a in (`xpath.bat t.xml "//property[@name='appbox2URL']/@value" `) do set "appbox2URL=%%a"

for /f "usebackq delims=* tokens=" %%a in (`xpath.bat t.xml "//property[@name='domainName']/@value" `) do set "domainName=%%a"

if /i "%appbox1URL%" equ "http://10.222.222.222" if /i "%appbox2URL%" equ "http://10.222.222.000" if /i "%domainName%" equ "xxxG" (
   call ant -buildfile "D:\xxx\Trunk\build.xml"
)

if /i "%appbox1URL%" equ "http://10.222.222.222" if /i "%appbox2URL%" equ "http://10.222.222.000" if /i "%domainName%" equ "OtherEnvironment" (
   call ant -buildfile "D:\xxx\Trunk\build.xml"
)
© www.soinside.com 2019 - 2024. All rights reserved.