XPath用于emma报告的概述值

时间:2012-06-23 08:41:24

标签: xpath emma

我在构建期间生成EMMA报告,它们看起来像这样

<report>
  <stats>
    <packages value="110"/>
    <classes value="1762"/>
    <methods value="12617"/>
    <srcfiles value="962"/>
    <srclines value="61320"/>
  </stats>
  <data>
    <all name="all classes">
      <coverage type="class, %" value="2%   (42/1762)"/>
      <coverage type="method, %" value="2%   (302/12617)"/>
      <coverage type="block, %" value="3%   (6849/258033)"/>
      <coverage type="line, %" value="3%   (1592.9/61320)"/>

我需要从/ report / data / all / coverage节点的值属性中获取百分比。目前得到这些:

Invalid XPath expression: "/report/data/all/coverage[starts-with(@type,'block')]@value": Unexpected '@'
Invalid XPath expression: "substring-before(/report/data/all/coverage[starts-with(@type,'block']@value,'%')": Expected: )

1 个答案:

答案 0 :(得分:2)

@value 属性之前,您缺少XPath的正斜杠。您的开头 - 功能

中也有一个缺少的括号

尝试以下

/report/data/all/coverage[starts-with(@type,'block')]/@value


substring-before(/report/data/all/coverage[starts-with(@type,'block')]/@value,'%')