【问题标题】:XPath Filter by DateXPath 按日期过滤
【发布时间】:2020-06-26 12:22:08
【问题描述】:

我需要通过 JAVA 类按日期过滤记录:

public static final String DATE_TIME = "DateTime"
Date dateNow = setTimeToZero(Calendar.getInstance().getTime());
String date = DATE_TIME_FORMAT.format(dateNow);
Request request = table.createRequest();

DATE_FILTER = XPathFilter.newFilter("date-greater-than(" + Root_Table_DateField.format() + '$date')");

request.setXPathFilter(DATE_FILTER);
request.setXPathParameter(DATE_TIME, date);

RequestResult = reqResult = request.execute();

我试图访问的字段定义为 DateTime,但我现在不想要时间,所以我将时间设置为零,所以我可以过滤所有日期大于 dd-MM-yyyT00 的字段: 00:00:000

但它返回一个谓词错误:PredicateException: Invalid XPath expresion ./dateTime = 26-06-2020T00:00:00:000 - Unexpected 'T00:00:00.000'

有什么线索吗?

谢谢

【问题讨论】:

    标签: java xpath predicate


    【解决方案1】:

    尝试添加格式为(xs:date("2020-06-26Z")的日期

    date-greater-than(xs:date("2004-12-25-12:00"), (xs:date("2020-06-26Z"))
    

    参考:https://www.w3.org/TR/xpath-functions-31/

    【讨论】:

    • 我快到了:xpath 的配置应该是 date-greater-than(path to the field, $PARAMETER) 所以,我所做的就是使用谓词 in一个 XPath 静态:StringBuilder 谓词 = new StringBuilder(); predicate.append("date-greater-than(") predicate.append(Path.To.Field.format()); predicate.append(", $"); predicate.append(DATE_PARAMETER); predicate.append() ); DATE_FILTER = XPathFilter.newFilter(true, predicate.toString());然后在另一个静态上,我在请求上调用 DATE 并执行请求。非常感谢!
    • 当然,我很高兴。很高兴看到你能弄明白!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 2019-03-01
    • 2016-01-10
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多