当我运行以下
时XPathFactory xpathFactory = XPathFactory.instance();
XPathExpression<Double> query =
xpathFactory.compile("count(1)", Filters.fdouble());
List<Double> result = query.evaluate(new Element("test"));
然而评估失败了:
无法评估表达式。看原因 原因:功能:计数
这是一个无意义的例子,但我想要一些自包含的东西。这有什么问题?
答案 0 :(得分:1)
如果您想计算test
元素的数量,请尝试此操作;
Element root = new Element("test");
Document doc = new Document(root);
XPathFactory xpathFactory = XPathFactory.instance();
XPathExpression<Double> query = xpathFactory.compile("count(//test)", Filters.fdouble());
List<Double> result = query.evaluate(doc);