Java XPath Select selectString(String xpath, Object node)

Here you can find the source of selectString(String xpath, Object node)

Description

select String

License

Open Source License

Declaration

public static String selectString(String xpath, Object node) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.xml.namespace.QName;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

public class Main {
    public static String selectString(String xpath, Object node) {
        return ((String) evaluateXPath(xpath, node, XPathConstants.STRING)).trim();
    }/*w ww  . jav  a 2s.co m*/

    public static Object evaluateXPath(String xpath, Object item, QName returnType) {
        try {
            return XPathFactory.newInstance().newXPath().compile(xpath).evaluate(item, returnType);
        } catch (XPathExpressionException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. selectNodeText(Node node, String expression)
  2. selectSingleElement(Element element, String xpathExpression)
  3. selectSingleNode(final Node node, final String xPath)
  4. selectSingleNode(final Node sourceNode, final String xPathExpression)
  5. selectSingleNode(Node node, String xpath, NamespaceContext context)
  6. selectStrings(String xpath, Object node)
  7. selectXPathString(final String xPath, final Node inNode, final String nsuri, final String pre)
  8. xmlSelectNodes(Node node, String xpathExpression)
  9. XPathAPI_selectNodeList(Document doc, String xpath, Node namespaceNode)