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

时间:2017-10-18 04:02:02

标签: xml batch-file

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

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

locations = new Array();
$.ajax({
    url:"jsonarray.php?id=2",
    type:"POST",
    dataType:"json",
    success:function(retqry){
        // locations = retqry;
        // console.log(locations);
        var Data = [];
        $.each(retqry, function(your_key, your_val){
            Data.push({
                your_key:your_val,
            });
        });

        locations = Data;
    } 
});

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

批处理文件中的Psudeo

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

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

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"

1 个答案:

答案 0 :(得分: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"
)