XPath中的计数函数 [英] Count function in XPath
本文介绍了XPath中的计数函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XML文档,并尝试使用xpath获取具有特定文本的节点数。请参见下面的xml
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)返回event_type节点的数量,但是我想要的是
具有错误文本的event_type节点的数量。
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>
感谢
推荐答案
count(//event_type[text()='Error'])
应该做的伎俩。此外,XPath的一个方便的工具: http://www.whitebeam.org/库/ guide / TechNotes / xpathtestbed.rhtm
should do the trick. Also, a handy tool for XPath : http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm
希望这有帮助。
这篇关于XPath中的计数函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文