Java Utililty Methods XPath Evaluate

List of utility methods to do XPath Evaluate

  1. HOME
  2. Java
  3. X
  4. XPath Evaluate

Description

The list of methods to do XPath Evaluate are organized into topic(s).

Method

Byte asByte(String expression, Node node)
Evaluates the specified XPath expression and returns the result as a Byte.
String byteString = evaluateAsString(expression, node);
return (isEmptyString(byteString)) ? null : Byte.valueOf(byteString);
Byte asByte(String expression, Node node)
Evaluates the specified XPath expression and returns the result as a Byte.
String byteString = evaluateAsString(expression, node);
return (isEmptyString(byteString)) ? null : Byte.valueOf(byteString);
String convertToXpath(String qname)
convert To Xpath
QName name = QName.valueOf(qname);
if ("".equals(name.getNamespaceURI())) {
 return "//" + name.getLocalPart();
} else {
 return "//*[local-name()='" + name.getLocalPart() + "' and namespace-uri()='" + name.getNamespaceURI()
 + "']";
Node evaluate(Document doc)
evaluate
return (Node) expression.evaluate(doc, XPathConstants.NODE);
String evaluate(File xmlFile, String xPathExpression)
evaluate
String result = null;
try {
 XPathFactory factory = XPathFactory.newInstance();
 XPath xPath = factory.newXPath();
 result = xPath.evaluate(xPathExpression, new InputSource(new FileInputStream(xmlFile)));
} catch (Exception ex) {
 System.out.println(ex.getMessage());
return result;
boolean evaluate(Node node, XPathExpression expression)
Evaluates the XPath expression in the specified context and returns whether such element was found.
try {
 Boolean result = (Boolean) expression.evaluate(node, XPathConstants.BOOLEAN);
 return result != null && result;
} catch (XPathExpressionException e) {
 return false;
T evaluate(Object obj, String xpathExpression, QName qName)
evaluate
try {
 return (T) xpath.compile(xpathExpression).evaluate(obj, qName);
} catch (XPathExpressionException e) {
 throw new RuntimeException(e);
String evaluate(String path, Node node)
evaluate
path = path.trim();
try {
 XPath xp = XPathFactory.newInstance().newXPath();
 XPathExpression expr = xp.compile(path);
 String ret = expr.evaluate(node);
 return ret;
} catch (Exception ex) {
 throw new RuntimeException(ex);
...
String evaluate(XPath xpath, String base, String path, Document document)
evaluate
try {
 return xpath.evaluate(base + "/" + path, document).trim();
} catch (Exception e) {
return null;
String evaluateAsString(String expression, Node node)
Evaluates the specified expression on the specified node and returns the result as a String.
if (isEmpty(node))
 return null;
if (!expression.equals(".")) {
 if (asNode(expression, node) == null)
 return null;
String s = xpath().evaluate(expression, node);
return s.trim();
...


AltStyle によって変換されたページ (->オリジナル) /