阅读与Windows批处理XML文件 [英] Read XML file with windows batch
问题描述
我试图读取XML文件,从XML文件生成标记之间阅读STRING50。我尝试过,但我没有收到任何输出。
I'm trying to read an xml file and read STRING "50" between the build tags from a XML file. I tried it but I'm not getting any output.
XML文件。
<?xml version="1.0" encoding="UTF-8"?>
<CDMDataXML xmlns="http://www.avocent.org/trellis/CDMLoaderXMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.avocent.org/trellis/CDMLoaderXMLSchema CDMLoaderXMLSchema.xsd">
<CDMDataVersion>
<Major>1</Major>
<Minor>0</Minor>
<Build>50</Build>
<Delimiter>.</Delimiter>
</CDMDataVersion>
该批处理文件code ..
The batch file code..
@ECHO OFF
SETLOCAL
SET "build="&SET "grab="
FOR /f "tokens=*" %%a IN (version.xml) DO (
IF DEFINED grab SET build=%%a&SET "grab="
IF /i "%%a"=="<BUILD>" SET grab=Y
)
ECHO found build=%build%
GOTO :EOF
请问code运行如果XML文件和批处理文件都位于同一个文件夹中,我从执行CMD批处理文件???
Will the code run if the xml file and the batch file are situated in the same folder and i execute the batch file from cmd???
编辑1:
@MC ND我让你提到的更改,跑到C $ C.当我按下回车键,光标移动到下一行,并卡住.......我不给任何输出,以及在$。我不能也关闭cmd窗口。所有这一切都是在下面的图片文件中解释说。
@MC ND I made the changes you mentioned and ran the code.When i hit enter, the cursor moves to the next line and gets stuck there.I doesn't give any output as well. I'm not able to close the cmd window also. All this is explained in the image file below.
答案
的建议通过以下MCND我重新命名文件findx.bat这是返回值50,这是我wanted.The正确的输出的屏幕截图下面给出。
As suggested by MCND below I renamed my file to findx.bat which is returning the value "50" which is what i wanted.The screen-shot of the correct output is given below.
非常感谢@MCND!
推荐答案
只检索所需的行(找到
),并使用adecuated分隔符(&LT;&GT;
),标记化行来检索所需信息
Retrieve only the required line (find
), and using the adecuated delimiters (<>
), tokenize the line to retrieve the required information
delims: v v v v
line : <Build>50</Build>
tokens:^1 ^2 ^3 ^4
现在,转化为code此
Now, translate this into code
@echo off
setlocal enableextensions disabledelayedexpansion
set "build="
for /f "tokens=3 delims=<>" %%a in (
'find /i "<Build>" ^< "file.xml"'
) do set "build=%%a"
echo %build%
这篇关于阅读与Windows批处理XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!