2

NodeList是这样实现的:

import java.util.ArrayList;
import java.util.Collections;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


public class MyNodeList  implements NodeList{

    //// local member  ... 
    ArrayList<Node> arrayNode   = new ArrayList<Node>() ; 
    ////

    @Override
    public int getLength() {
        return arrayNode.size() ; 
    }

    @Override
    public Node item(int index) {
        return (arrayNode.get(index)).cloneNode(true); 
    }

    public void reverse ()  {
        Collections.reverse(arrayNode);
    }

    public void castNodeToMyNode (NodeList nodeListToCast) {
        int lenList = nodeListToCast.getLength();
        for (int i = 0; i < lenList; i++) {
            this.arrayNode.add(nodeListToCast.item(i)) ; 
        }
    }
    public void appendNodeList (NodeList nodeListToappend) {
        this.castNodeToMyNode(nodeListToappend)  ; 
    }

}

我必须这样做,因为我需要方法reverse - 修改NodeList.

我的问题是:什么时候使用evaluate功能-Object result = xpath.evaluate(expression, source, XPathConstants.NODESET);

我想在实现时设置source参数。可以将 设置为when 是 的对象吗?我做了这样的事情,但我认为这对.itemMyNodeListsourcecmyNodeAfterProbExp.item(indexOfNode)myNodeAfterProbExpMyNodeListevaluate

提前致谢。

4

0 回答 0