Xpath querying in C# - range check.
Hi all,
I store some data in XML, along with the date it was created. The Datetime.Ticks property has the no; of ticks since the year 1100. I want to allow the users to select a date range and display data for the selected dates to be filtered. I use Ticks to select nodex based on that, it works.
so, //Tasks/task[@Ticks>16588372930411]" works , note that ticks is a long type.
But using ticks to compares does NOT work Like:
//Tasks/task[@Ticks>16588372930411 and @Ticks<83744578232].
Is my xpath query wrong? how do we apply a between x and Y operator here. Iam doing this in C#. Any help would be greatly appreciated. Thank you.
CT.
Re: Xpath querying in C# - range check.
Considering that 16588372930411 is bigger than 83744578232 how do you expect something to be bigger than 16588372930411 and smaller than 83744578232?
Try using 'or' instead of 'and', other than that the syntax looks okay.
Re: Xpath querying in C# - range check.
Thank you for the reply. I just gave those numbers as an example. So I use Dattime.Ticks property to make the comparisons. So, if they select Apr 25, 2010 to May 5, 2010, then I use
long x = Datetime.Parse("APR 25 2010").Ticks
and long y Dattime.Parse("May 5 2010").Ticks property to make the comparisons. I assume Ticks of May would be higher than those Apr 2010, since the ticks are adding from Jan 1, 1100 or so. I use
i//Tasks/Task[@Ticks>=x and @Ticks<=y] to make comparisons, coz I dont know how else to compare dates in XML. Is there any other way, or am I wrong in assuming ticks of May 2010 is higher than Apr 2010. Wonder if its reset somewhere, I dont think so but.
Any help would be greatly appreciated - thank you.
CT.
Re: Xpath querying in C# - range check.
Quote:
Originally Posted by Charu0306
I dont know how else to compare dates in XML
Currently XPath 1.0 does not support date comparison. You can try to use Saxon's XPath 2.0 implementation or you can try Adding Custom Functions to XPath that will compare dates.
Quote:
Originally Posted by Charu0306
am I wrong in assuming ticks of May 2010 is higher than Apr 2010?
Feel free to test it.
Re: Xpath querying in C# - range check.
Quote:
Originally Posted by
someuser77
Currently XPath 1.0 does not support date comparison. You can try to use
Saxon's XPath 2.0 implementation or you can try
Adding Custom Functions to XPath that will compare dates.
Feel free to test it.
Thanks, Iam comparing them after retrieving them , and converting them to DateTime.
And yes, Ticks are not progressive, so Apr 2010's ticks are < than May 2010 ticks. :confused: