Java XPath Evaluate getNodesListXpath(final String xPathS, final Node node, final String nsuri, final String pre, final QName returnType)

Here you can find the source of getNodesListXpath(final String xPathS, final Node node, final String nsuri, final String pre, final QName returnType)

Description

get Nodes List Xpath

License

Apache License

Parameter

Parameter Description
xPathS a parameter
node a parameter
nsuri a parameter
pre a parameter
returnType a parameter

Exception

Parameter Description
Exception an exception

Return

Return type is one of XPathConstants .BOOLEAN, .NODE, .NODESET, .NUMBER, .STRING

Declaration

public static Object getNodesListXpath(final String xPathS, final Node node, final String nsuri,
        final String pre, final QName returnType) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.xml.namespace.QName;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Node;

public class Main {
    public static final String XPATH_FACTORY = "net.sf.saxon.xpath.XPathFactoryImpl";

    /**/*www. j a va  2s  . co m*/
     * 
     * @param xPathS
     * @param node
     * @param nsuri
     * @param pre
     * @param returnType
     * @return Return type is one of XPathConstants .BOOLEAN, .NODE, .NODESET,
     *         .NUMBER, .STRING
     * @throws Exception
     */
    public static Object getNodesListXpath(final String xPathS, final Node node, final String nsuri,
            final String pre, final QName returnType) throws Exception {
        Object matches = null;
        System.setProperty("javax.xml.xpath.XPathFactory:" + XPathConstants.DOM_OBJECT_MODEL, XPATH_FACTORY);

        XPathFactory xpathFactory = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
        XPath xpath = xpathFactory.newXPath();
        XPathExpression xpe = xpath.compile(xPathS);
        matches = xpe.evaluate(node, returnType);

        return matches;
    }
}

Related

  1. evalXPathAsStringList(Object item, String xpath, XPathFactory factory, boolean includeDuplicates)
  2. executeXPath(Document dom, String xpath, QName returnType)
  3. executeXPathExpression(Document document, String expression)
  4. execXPath(org.w3c.dom.Node node, String pattern, QName xPathConstantsType)
  5. findNodeAndGetXPath(String qName, String fileName)
  6. parseVariable(Node contextNode, String xPathString)
  7. xPath(final Node aNode, final String anXPath, final QName aQName)
  8. xpathEvalElements(String expr, Object e)
  9. xpathEvalNodes(String expr, Object e)