CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    223

    Question 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.

    [If you find my answers useful, please leave your comments and rating for it.]
    Happy Coding!
    My Dev.: MS VS 2005 Version 8.0.50727.42 .NET 2.0.50727
    Mark your answers Tools>>RESOLVED once its answered.

  2. #2
    Join Date
    Mar 2007
    Posts
    90

    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.

  3. #3
    Join Date
    Mar 2004
    Posts
    223

    Smile 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.

    [If you find my answers useful, please leave your comments and rating for it.]
    Happy Coding!
    My Dev.: MS VS 2005 Version 8.0.50727.42 .NET 2.0.50727
    Mark your answers Tools>>RESOLVED once its answered.

  4. #4
    Join Date
    Mar 2007
    Posts
    90

    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.

  5. #5
    Join Date
    Mar 2004
    Posts
    223

    Re: Xpath querying in C# - range check.

    Quote Originally Posted by someuser77 View Post
    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.

    [If you find my answers useful, please leave your comments and rating for it.]
    Happy Coding!
    My Dev.: MS VS 2005 Version 8.0.50727.42 .NET 2.0.50727
    Mark your answers Tools>>RESOLVED once its answered.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured