Java XPath Evaluate evaluateXpath(String expression, Object node, QName returnType, NamespaceContext nsContext)

Here you can find the source of evaluateXpath(String expression, Object node, QName returnType, NamespaceContext nsContext)

Description

evaluate Xpath

License

Open Source License

Declaration

public static Object evaluateXpath(String expression, Object node, QName returnType, NamespaceContext nsContext)
            throws XPathExpressionException 

Method Source Code


//package com.java2s;
/*-****************************************************************************** 
 * Copyright (c) 2014 Iwao AVE!./* w w w  . j a  va  2s . c o  m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Iwao AVE! - initial API and implementation and/or initial documentation
 *******************************************************************************/

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;

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

public class Main {
    public static Object evaluateXpath(String expression, Object node, QName returnType, NamespaceContext nsContext)
            throws XPathExpressionException {
        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();
        if (nsContext != null) {
            xpath.setNamespaceContext(nsContext);
        }
        return xpath.evaluate(expression, node, returnType);
        // XPathExpression xpathExpr = xpath.compile(expression);
        // return xpathExpr.evaluate(node, returnType);
    }
}

Related

  1. evaluateXpath(Element from, String xpath)
  2. evaluateXPath(final String xPath, final Object item, final QName returnType)
  3. evaluateXPath(final XPathExpression expr, final Object rootNode, final QName returnType)
  4. evaluateXPath(Node node, String xPath)
  5. evaluateXpath(String expression, Document document, QName dataType)
  6. evaluateXPath(String path, Node e, QName type)
  7. evaluateXPath(String xpath, Object item, QName returnType)
  8. evaluateXPathAsNodeList(String expression, Document document)
  9. evaluateXPathBool(final Node inNode, final String xpath)