小编Wal*_*lid的帖子

计算XPath中的函数

我有一个XML文档,并尝试使用xpath获取具有特定文本的节点数.见下面的xml

count(// event_type)返回event_type节点的数量,但我想要的是具有Error文本的event_type节点的数量.

  <Response>
    <run_id>20091231-105000</run_id>
    <message>
      <timestamp>2009-12-31T10:50:00.46875+00:00</timestamp>
      <event_type>Information</event_type>
      <operation>LoadProjects</operation>
      <error_code />
      <details>LoadProjects request detected</details>
    </message>
    <message>
      <timestamp>2009-12-31T10:50:02.296875+00:00</timestamp>
      <event_type>Error</event_type>
      <operation>Processor.InitaliseDCFiles</operation>
      <error_code />
      <details>some error details</details>
    </message>
    <message>
      <timestamp>2009-12-31T10:50:02.296875+00:00</timestamp>
      <event_type>Debug</event_type>
      <operation>Processor.InitaliseDCFiles</operation>
      <error_code />
      <details>some details</details>
    </message>
  <Response>  
Run Code Online (Sandbox Code Playgroud)

谢谢

xml xpath count

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

count ×1

xml ×1

xpath ×1