从批处理中读取xml
我正在尝试使用批处理 (.bat) 文件读取 xml 文件,并且搜索了多个站点但没有成功的解决方案。
XML 文件结构:
<parameter>
<name>myname</name>
<value>1234</value>
</parameter>
尝试的批处理代码:
FOR /f "tokens=2 delims=<>" %%i in ('type "sample.xml" ^|find "myname"') do set "value=%%i"
echo %value%
... 然后重复,每个批处理代码都有自己的名称和值。
我想要做的是使用名称作为搜索条件来获取值。
我无法分享我所尝试的内容,因为我正在使用手机发送此信息。
I am trying to read an xml file using a batch (.bat) file and have searched multiple sites without a successful solution.
XML file structure:
<parameter>
<name>myname</name>
<value>1234</value>
</parameter>
Attempted batch code:
FOR /f "tokens=2 delims=<>" %%i in ('type "sample.xml" ^|find "myname"') do set "value=%%i"
echo %value%
... And then repeats with each one having its own name and value.
What I want to do is get the value using the name as the search criteria.
I can't share what I have tried as I am using my phone to send this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您问题的核心点是您想要获取您找到的行之后的下一行。有很多方法可以实现这一点。下一个是一个非常简单的方法:
当然,如果.xml 文件具有不同的格式,则此方法将不起作用...
这是一个完整的测试。这是程序 test.bat:
这是我在测试中使用的 sample.xml 文件:
这是测试:
The core point of your problem is that you want to get the next line after the one you located. There are a lot of methods to achieve this. The next one is a pretty simple one:
Of course, if the .xml file have a different format, this method will not work...
Here it is a complete test. THis is the program test.bat:
This is the sample.xml file I used in the test:
And this is the test: