Question

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?

Was it helpful?

Solution

/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
}

OTHER TIPS

//Events/Event[contains(DateTime,'22.09.2009') and EventType='Download']
/Events/Event[substring(DateTime, 0, 10)='22.09.2009' and EventType='Download']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top