1

一部のルート オブジェクトにはフィールドがありますMyCollection myCollection。クラスはインターフェイスをMyCollection実装しCollectionます。要素の名前は呼び出すことで利用できるので、クラスsomeService().getName()を作成しました。Rules

context.getValue("/myCollection"); myCollection を返します - OK

context.getValue("//myCollection"); myCollection を返します - OK

context.getValue("/myCollection/.[rules:getName() = 'secondName']");「secondName」を返すIMyNodeインスタンスを 返します - OKsomeService().getName()

context.getValue("/myCollection//.[rules:getName() = 'secondName']"); の後、次の行は実行されません。また例外なく、寛大なモードは設定されていません。何が起こっているのかわかりません。クラスの 8 行目は、 をRules印刷し"POINTER SET ON /myCollection[1]"ます。この例で取得したい要素は にあり/myCollection[2]ます。

これは、要素の名前が取得される場所です。このクラスは正しいと思います。

public class Rules {
public static String getName(ExpressionContext context){
   Pointer pointer = context.getContextNodePointer();
    if(pointer == null){
        return "";
    } else {
        if(pointer.getValue() instanceof IMyNode){
        System.out.println("POINTER SET ON " + pointer);
            IMyNode node = (IMyNode)pointer.getValue();
           return node.someService().getName();
       }
   }
   return "";
}
}

編集: この質問はJXPathに関するものです。jxpath の代わりに xpath タグを追加するのは間違っていました。

4

1 に答える 1

1

*の代わりに使用してみてください.local-name()また、代わりに標準の XPath 関数を使用できると思いますrules:getName()

于 2012-11-18T00:09:59.773 に答える