Java 怎么将xpath转为节点

2019年8月7日21:03:08Java 怎么将xpath转为节点已关闭评论 461 379字阅读1分15秒

1.简介

Java 怎么将xpath转为节点?——请看下文。

2.示例代码

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

 


import javax.xml.xpath.*;
import org.w3c.dom.*;

public class Main {
    public static Node xpathToNode(String xpathQuery, Object domObject)
            throws XPathExpressionException {
        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();

        return (Node) xpath.evaluate(xpathQuery, domObject,
                XPathConstants.NODE);
    }
}

 
编程十万个怎么办