Java 怎么评估xpath并返回节点

2019年7月29日20:58:22Java 怎么评估xpath并返回节点已关闭评论 427 447字阅读1分29秒

1.简介

Java 怎么评估xpath并返回节点?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */



import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Node;

public class Main {
    public static Node xPathNodeList(Node node, String path)
            throws XPathExpressionException {
        XPath xpath = XPathFactory.newInstance().newXPath();
        return (Node) xpath.evaluate(path, node, XPathConstants.NODE);
    }
}

 
编程十万个怎么办