要根据子元素的组合进行匹配的XPath查询

时间:2009-09-22 13:13:22

标签: xpath matching

给出以下XML Snippet

 <Events>
    <Event>
     <DateTime>22.09.2009 11:27:18</DateTime>
     <EventType>Download</EventType>
 </Event>

什么是XPath查询以返回今天创建的类型下载的所有事件?

3 个答案:

答案 0 :(得分:3)

/Events/Event[starts-with(DateTime, '22.09.2009') and EventType='Download']

由于我认为这是对上一个问题的跟进,您可能希望使用此代码段而不是SelectSingleNode来获取文件中的所有事件(如果可能有多个):

foreach (XPathNavigator node in doc.CreateNavigator().Select(expression)) {
    // matching node found in document; will process all matching nodes
}

答案 1 :(得分:1)

//Events/Event[contains(DateTime,'22.09.2009') and EventType='Download']

答案 2 :(得分:1)

/Events/Event[substring(DateTime, 0, 10)='22.09.2009' and EventType='Download']