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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With