3

VTD-XML 2.11 (Java) API を使用count(//b)して、XML ドキュメントの XPath 式を評価する<a><b/><b/></a>と、代わりに の結果が得2.0られ、次の例外で失敗します。

com.ximpleware.XPathEvalException:  Function Expr can't eval to node set
   at com.ximpleware.FuncExpr.evalNodeSet(FuncExpr.java:1033)
   at com.ximpleware.AutoPilot.evalXPath(AutoPilot.java:876)
   at ...testVTDXMLXPathFunctionCount(TestVTDXMLXPath.java:107)

問題を再現するための非常に単純なテスト ケースを次に示します。

public void testVTDXMLXPathFunctionCount() throws Exception {
    AutoPilot autoPilot = new AutoPilot();
    try {
        VTDGen document = new VTDGen();
        document.setDoc("<a><b/><b/></a>".getBytes());
        document.parse(true);
        VTDNav navigator = document.getNav();
        autoPilot.selectXPath("count(//b)");
        autoPilot.bind(navigator);
        int j;
        while ((j = autoPilot.evalXPath()) != -1) {
            System.out.println(navigator.toNormalizedXPathString(j));
        }
    } catch (XPathParseException e) {
        e.printStackTrace();
    } catch (XPathEvalException e) {
        e.printStackTrace();
    } catch (NavException e) {
        e.printStackTrace();
    } finally {
        autoPilot.resetXPath();
    }
}

count() 関数は、有効な XPath 1.0 式ですが、VTD-XML で XPath 式の開始として使用できないようです。

どんなヒントでも大歓迎です。

4

1 に答える 1

1

evalXPathToNumberの代わりにuse を使用してみてくださいselectXPath

于 2013-01-29T23:40:28.040 に答える