示例 XML:
<test name="1" result="Passed" starttimestamp="2013-05-07 10:10:44.361 -0700" endtimestamp="2013-05-07 10:10:45.361 -0700" elapsed="1" />
<test name="2" result="Passed" starttimestamp="2013-05-07 10:10:45.362 -0700" endtimestamp="2013-05-07 10:10:46.362 -0700" elapsed="1" />
<test name="3" result="Passed" starttimestamp="2013-05-07 10:10:46.363 -0700" endtimestamp="2013-05-07 10:10:53.365 -0700" elapsed="7" />
<test name="4" result="Passed" starttimestamp="2013-05-07 10:10:53.365 -0700" endtimestamp="2013-05-07 10:11:39.374 -0700" elapsed="46" />
首先,我试过
xpath somefile.xml test
它给了我:
<test name="1" result="Passed" starttimestamp="2013-05-07 10:10:44.361 -0700" endtimestamp="2013-05-07 10:10:45.361 -0700" elapsed="1" />-- NODE --
<test name="2" result="Passed" starttimestamp="2013-05-07 10:10:45.362 -0700" endtimestamp="2013-05-07 10:10:46.362 -0700" elapsed="1" />-- NODE --
<test name="3" result="Passed" starttimestamp="2013-05-07 10:10:46.363 -0700" endtimestamp="2013-05-07 10:10:53.365 -0700" elapsed="7" />-- NODE --
<test name="4" result="Passed" starttimestamp="2013-05-07 10:10:53.365 -0700" endtimestamp="2013-05-07 10:11:39.374 -0700" elapsed="46" />-- NODE --
然后我想计算所有通过的测试,即所有具有参数的节点"Passed"
。所以我使用了以下 xpath 表达式:
xpath somefile.xml count(test[@result="Passed"])
但是它给了我:
bash:意外标记'('附近的语法错误
然后我尝试了
xpath somefile.xml test[@result="Passed"]
它说:
未找到节点