【问题标题】:Find XML element available using xlint -- xpath使用 xlint -- xpath 查找可用的 XML 元素
【发布时间】:2019-08-12 08:15:27
【问题描述】:

这是我的 XML,我正在使用 xmllint(在 bash 脚本文件中解析 xml)来查找 xml 中存在的元素。

<testsuite name="com.myapp.testcases.loginTest">

    <testcase name="invalidIdTest" classname="com.myapp.testcases.loginTest" time="0.002">
        <skipped/>
    </testcase>

    <testcase name="invalidTokenTest" classname="com.myapp.testcases.loginTest" time="4.164"/>

    <testcase name="connectAndDisconnectTest" classname="com.myapp.testcases.loginTest" time="13.622">
    </testcase>
    <testcase name="invalidServerUrlTest" classname="com.myapp.testcases.loginTest" time="40.072"/>
</testsuite>

我想知道testcase元素是否有子元素skipped? 如果我尝试了以下命令,但它为所有 4 个 testcase 元素提供了空输出。

val=$(xmllint --xpath 'string(testsuite/testcase/*[local-name()="skipped"])' skipped.xml)
echo $val

也试过了

isSkipped=$(xmllint --xpath "string(/testsuite/testcase[$i][skipped])" skipped.xml)

如果testcase 元素有skipped 子元素,我想打印 1,否则为 0。 请帮我解决这个问题

【问题讨论】:

    标签: xml xpath xmllint


    【解决方案1】:

    如果testcase 元素有skipped 子元素,我想打印 1 否则 0

    number(boolean(/testsuite/testcase[skipped]))
    

    请注意,这适用于整个文档:“是否有 testcaseskipped 孩子”。

    【讨论】:

      猜你喜欢
      • 2020-05-19
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多