Java XPath Get getElementByXpath(Element sourceRoot, String xpathExpress)

Here you can find the source of getElementByXpath(Element sourceRoot, String xpathExpress)

Description

get Element By Xpath

License

Apache License

Declaration

public static Element getElementByXpath(Element sourceRoot, String xpathExpress)
            throws XPathExpressionException 

Method Source Code

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

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

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    private static final XPathFactory XPATH_FACTORY = XPathFactory.newInstance();

    public static Element getElementByXpath(Element sourceRoot, String xpathExpress)
            throws XPathExpressionException {
        XPath xPath = XPATH_FACTORY.newXPath();
        NodeList nodes = (NodeList) xPath.evaluate(xpathExpress, sourceRoot, XPathConstants.NODESET);
        if (nodes.getLength() > 0)
            return (Element) nodes.item(0);
        return null;
    }//from  w  w  w. j av  a 2  s . c  o  m
}

Related

  1. getCertificateFromKeyInfo(Node keyInfoNode)
  2. getCruxPagesXPath()
  3. getDefaultXPath()
  4. getDefaultXPathFactory()
  5. getDigestValue(Node reference)
  6. getElementsByXPath(Element parent, String name)
  7. getElementXPath(Node elt)
  8. getExcelPath()
  9. getFactory()