forked from LupusNobilis/java-org.hwo
45 lines
896 B
Java
45 lines
896 B
Java
package org.hwo.xml;
|
|
|
|
import javax.xml.xpath.XPath;
|
|
import javax.xml.xpath.XPathConstants;
|
|
import javax.xml.xpath.XPathExpressionException;
|
|
import javax.xml.xpath.XPathFactory;
|
|
|
|
import org.hwo.logging.Logging;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
public class XMLHelper {
|
|
|
|
static XPath _xpath;
|
|
|
|
|
|
public static NodeList select(Node node,String xpath){
|
|
try {
|
|
return (NodeList)_xpath.evaluate(xpath, node, XPathConstants.NODESET);
|
|
} catch (XPathExpressionException e) {
|
|
Logging.log(e);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static Element firstNamedElement(Node node,String name){
|
|
try {
|
|
return (Element)_xpath.evaluate(name, node, XPathConstants.NODE);
|
|
} catch (XPathExpressionException e) {
|
|
Logging.log(e);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
static {
|
|
_xpath = XPathFactory.newInstance().newXPath();
|
|
}
|
|
|
|
|
|
}
|