tags:

views:

76

answers:

1

I have got an XML document and trying to get the number of nodes that have a particular text using xpath. see xml below

count(//event_type) returns the number of event_type nodes but what I want is the number of event_type nodes that have the Error text.

  <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>  

Thanks

+3  A: 
count(//event_type[text()='Error']) 

should do the trick. Also, a handy tool for XPath : http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm

Hoping this helps.

phtrivier
+1, but he wants `count(//event_type[text()='Error'])`
Michael Krelin - hacker
Thanks, I had forgotten it the first time.
phtrivier
Thanks a lot. It works.
Walid