给定以下 XML 片段
<Events>
<Event>
<DateTime>22.09.2009 11:27:18</DateTime>
<EventType>Download</EventType>
</Event>
返回今天创建的所有下载类型事件的 XPath 查询是什么?
/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
}
//Events/Event[contains(DateTime,'22.09.2009') and EventType='Download']
/Events/Event[substring(DateTime, 0, 10)='22.09.2009' and EventType='Download']