XPath query to match depending on combinations of child elements

狂风中的少年 提交于 2019-12-25 04:38:06

问题


Given the following XML Snippet

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

What is the XPath query to return all Events created today of type download?


回答1:


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

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
}



回答2:


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



回答3:


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


来源:https://stackoverflow.com/questions/1460028/xpath-query-to-match-depending-on-combinations-of-child-elements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!