【问题标题】:Read value Inside tags from xml using Batch Script使用批处理脚本从 xml 读取值内部标签
【发布时间】:2012-08-27 11:51:58
【问题描述】:

示例:在 test.xml 中,我有

   <head>
    <file name="input">
        <above>
              <tag point="x"/>
        </above>
        <below> 
              <result first="00"/>
        </below>
    </file>
    <file name="output">
        <above> 
              <tag point="y"/> 
        </above>
        <below> 
              <result first="11"/> 
        </below>
    </file>
   </head>

我应该在批处理脚本中读取这个 XML,我应该在其中获得值 "11" 。 这个“11”在标签中的标签内找到。

我只需要在上面指定的路径中获取值“11”。

这是一个示例,在实际场景中,“11”可以有不同的值。

提前致谢

【问题讨论】:

  • 一个建议:使用 Perl。它有许多有用的解析模块,如HTML::ParserDOMSAX 等,可以解决您所有的HTML/XML 解析问题。

标签: xml tags batch-file


【解决方案1】:
FOR /F tokens^=2^ delims^=^" %%A in ('find "result first=" test.xml') do echo:%%A

或在命令提示符下:

fOR /F tokens^=2^ delims^=^" %A in ('find "result first=" test.xml') do echo:%A

只有当您的文件结构如上(特别是新行)时,这才有效。 最好使用 xml startlet http://xmlstar.sourceforge.net/ 。更多关于 for 技巧的信息 - >

http://ss64.org/viewtopic.php?id=1544

http://ss64.org/viewtopic.php?id=1572

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多