Search code examples
xquerymarklogic

Find the documents which have element in proper "dateTime" format


I am trying the following query in marklogic-9:

cts:element-value-match(xs:QName("cd:modificationDate"), "[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].000Z", ("type=dateTime","timezone=TZ"))

to achieve this, but this gives me the following error:

[1.0-ml] XDMP-ARG: cts:element-value-match(xs:QName("cd:modificationDate"), "[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].000Z", ("type=dateTime", "timezone=TZ")) -- arg2 is invalid

What i want to do is to find out all those documents which conforms to this specific pattern of dateTime. We have a date-range index on this element - modificationDate.

How best can we do this using marklogic and xquery api.


Solution

  • cts:element-value-match is really only useful on string range indexes and even there it only takes simple wildcards (* and ?), not general regular expressions or date formats.

    If your range index is a dateTime range index, then every value must conform to the proper xs:dateTime format, so this query would tell you nothing.

    This will give you a list of all the URIs where you have a valid dateTime in that element:

    cts:uris("", (),
        cts:element-range-query(xs:QName("modificationDate"), ">", xs:dateTime("0001-01-01T00:00:00"))
    )