示例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:意外令牌附近的语法错误`(&#39;
然后我试了
xpath somefile.xml test[@result="Passed"]
它说:
找不到节点
答案 0 :(得分:6)
我强烈怀疑这只是bash
处理您的命令行参数的问题,而不是您期望的方式。试试这个:
xpath somefile.xml 'count(test[@result="Passed"])'
这样,整个第二个命令行参数应该没有任何特殊含义(
,[
等。