0

私が現在サポートしている通常のクエリは、ルートからのものです。つまり、次のことを意味します。

public Object evaluate(String expression, QName returnType) {...}

ここで、特定の Node から始まる Xpath クエリを実行したいと思います。

public Object evaluate(String expression, Node source, QName returnType) { ? } 

次に、私の通常のクエリが次のようになっている場合(ここに例があります):

//load the document into a DOM Document
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); // never forget this!
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse("books.xml");
//create an XPath factory
XPathFactory factory = XPathFactory.newInstance();
//create an XPath Object
XPath xpath = factory.newXPath();

//make the XPath object compile the XPath expression
XPathExpression expr = xpath.compile("/inventory/book[3]/preceding-sibling::book[1]");
//evaluate the XPath expression
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
//print the output
System.out.println("1st option:");
for (int i = 0; i < nodes.getLength(); i++) {
    System.out.println("i: " + i);
    System.out.println("*******");
    System.out.println(nodeToString(nodes.item(i)));
    System.out.println("*******");

上記の方法でこれを実現するには、どのような変更が必要ですか ( public Object evaluate(String expression, Node source, QName returnType);)

ありがとう!

4

0 に答える 0