XmlDocument filter nodes by datetime string
Trying to apply filter / attribute comparison in the Xmldocument. Obviously , the following code snippet w开发者_JAVA技巧ouldn't work because the expression can't be converted using number() function. (according to the answer of my other question).
I'm wondering if there is a way to do the DateTime string comparison in XmlDoc.
XmlNodeList test = x2PathDoc.SelectNodes("//Config
/Entity
[@TargetDateTime>
'2010-12-19T03:25:00-08:00']");
When doing comparisons, xpath converts the parameters to numbers. Since '2010-12-19T03:25:00-08:00' cannot be converted to a number, SelectNode returns an empty list.
If you were to store the date in a different format so that it could be converted to a number, then you would be fine. see the example below: the date format is yyyymmdd.hhmmss
var root = new XmlDocument();
root.LoadXml(@"<dates><date value=""20060419.201500""/><date value=""20060420.201500""/><date value=""20060421.201500""/></dates>");
var node = root.SelectNodes(@"dates/date[@value < 20060421.235959]")I
精彩评论