Re: XPath Comparisons

Discussion in 'XML' started by Martin Honnen, Dec 15, 2008.

  1. Bubba wrote:

    > I'm writing an application that creates dynamic XPath queries to extract
    > information from a custom log file. However, when I try to execute
    > /Log/Item[@Date <= 'dd/mm/yyyy'] I never get any results returned (but
    > the expression work in Stylus Studio Pro 2009) but a similar
    > /Log/Item[@Date = 'dd/mm/yyyy'] does.

    With XPath 1.0 the comparison operators <, >, <=, >= work only on
    numbers so they convert their operands to numbers if they are not
    already numbers. Converting 'dd/mm/yyyy' to a number is not possible.

    With XPath 2.0 you can do such comparisons for other types including
    xsd:date and xsd:dateTime, however the xsd:date format is yyyy-mm-dd. So
    with XPath 2.0 you could do
    /Log/Item[xsd:date(@Date) <= xsd:date('2008-12-15')]

    XPath 2.0 is supported by Saxon 9 which comes in a Java and in a .NET
    version, see


    Martin Honnen
    Martin Honnen, Dec 15, 2008
    1. Advertisements

  2. Bubba wrote:

    > Hi, thanks for your reply but I'm still no further forward; having
    > created a Schema for the document and defining @Date as xs:date and
    > @Time as xs:Time I still get no results when I execute this:
    > /Log/Item[@Date >= '2008-12-15' and @Time > '17:00']
    > Even though the expression works perfectly in Stylus Studio I still get
    > nothing returned via C++! Is system.xml.dll in Windows the problem do I
    > need to buy a 3rd party processor?

    I clearly explained the differences between XPath version 1.0 and XPath
    version 2.0.

    Whether you use C++ does not matter, what matters is the XPath version
    that your XPath API supports. If you use the .NET framework's
    XPathDocument/XPathNavigator then I am afraid they support XPath 1.0
    only. The same holds for Microsoft's MSXML, even MSXML 6 does only
    support XPath 1.0 and not 2.0.

    As for buying a third party processor, Saxon comes in two versions, the
    open source basic version and the commercial SA version. Doesn't Stylus
    Studio come with Saxon so that you might already have that? Ask in a
    Stylus Studio support forum.
    And AltovaXML tools can be downloaded and installed without a fee.


    Martin Honnen
    Martin Honnen, Dec 15, 2008
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    Mike Schilling
    Jun 27, 2005
  2. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    jan V
    Jul 29, 2005
  3. Alastair Cameron
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  4. Anna
  5. Nishad
    Dimitre Novatchev
    Sep 30, 2006

Share This Page