问题
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