XPath查询根据子元素的组合进行匹配 [英] XPath query to match depending on combinations of child elements
本文介绍了XPath查询根据子元素的组合进行匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下XML代码段
<Events>
<Event>
<DateTime>22.09.2009 11:27:18</DateTime>
<EventType>Download</EventType>
</Event>
返回今天创建的所有类型为下载的所有事件的XPath查询是什么?
What is the XPath query to return all Events created today of type download?
推荐答案
/Events/Event[starts-with(DateTime, '22.09.2009') and EventType='Download']
由于我假设这是您上一个问题的后续内容,因此您可能希望使用此代码段而不是SelectSingleNode来获取文件中的所有事件(如果可以有多个事件):
Since I assume that this is a follow-up to your previous question, you might want to use this snippet instead of SelectSingleNode to get all events in a file (if there can be multiple):
foreach (XPathNavigator node in doc.CreateNavigator().Select(expression)) {
// matching node found in document; will process all matching nodes
}
这篇关于XPath查询根据子元素的组合进行匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文