Java Utililty Methods XPath Get

List of utility methods to do XPath Get

Description

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

Method

StringgetORSVersion()
get ORS Version
String version = null;
try {
    String curDir = System.getProperty("user.dir");
    Path pomFile = Paths.get(Paths.get(curDir).getParent().toString(), "openrouteservice")
            .resolve("pom.xml");
    try (InputStream is = Files.newInputStream(pomFile)) {
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
        doc.getDocumentElement().normalize();
...
StringgetProcessIdFromBpmn(final String bpmn)
get Process Id From Bpmn
String processId = null;
try {
    final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true);
    final Document doc = domFactory.newDocumentBuilder()
            .parse(new ByteArrayInputStream(bpmn.getBytes("UTF-8")));
    final XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(new NamespaceContext() {
...
PublicKeygetPublicKeyFromKeyInfo(Node keyInfoNode)
get Public Key From Key Info
PublicKey publicKey = null;
try {
    String modulusString = keyModulusPath.evaluate(keyInfoNode);
    String exponentString = keyExponentPath.evaluate(keyInfoNode);
    if (modulusString == null || exponentString == null) {
        return null;
    byte[] modulusBytes = Base64.decodeBase64(modulusString);
...
StringgetResultXpathstring(String expr, InputSource inputSource)
get Result Xpathstring
XPathExpression xExpr = xPath.compile(expr);
return xExpr.evaluate(inputSource);
MapgetScrProperties(String componentName)
get Scr Properties
return getScrProperties(String.format("target/classes/OSGI-INF/%s.xml", componentName), componentName);
NodegetSearchHandlerNode(final File solrconfig)
Get the searchHandler Node from the solrconfig.xml file
final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
final Document docSchem = dBuilder.parse(solrconfig);
final XPathFactory xPathfactory = XPathFactory.newInstance();
final XPath xpath = xPathfactory.newXPath();
final XPathExpression expr = xpath
        .compile("//requestHandler[@class=\"solr.SearchHandler\" and @name=\"/select\"]");
final Node requestHandler = (Node) expr.evaluate(docSchem, XPathConstants.NODE);
...
XPathgetSharedXPath()
get Shared X Path
XPath xPath = null;
if (sharedXPath != null)
    xPath = sharedXPath.get();
if (xPath == null) {
    XPathFactory xPathFactory = XPathFactory.newInstance();
    sharedXPath = new SoftReference<XPath>(xPath = xPathFactory.newXPath());
return xPath;
...
StringgetSpeficValueFromNode(Node n, String xpathExpr)
get Spefic Value From Node
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(ihcNamespaceContext);
XPathExpression pathExpr = xpath.compile(xpathExpr);
return (String) pathExpr.evaluate(n, XPathConstants.STRING);
StringgetStrFromNode(Node xpathnode)
Method getStrFromNode
if (xpathnode.getNodeType() == Node.TEXT_NODE) {
    StringBuilder sb = new StringBuilder();
    for (Node currentSibling = xpathnode.getParentNode()
            .getFirstChild(); currentSibling != null; currentSibling = currentSibling.getNextSibling()) {
        if (currentSibling.getNodeType() == Node.TEXT_NODE) {
            sb.append(((Text) currentSibling).getData());
    return sb.toString();
} else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
    return ((Attr) xpathnode).getNodeValue();
} else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
    return ((ProcessingInstruction) xpathnode).getNodeValue();
return null;
StringgetStrFromNode(Node xpathnode)
Method getStrFromNode
if (xpathnode.getNodeType() == Node.TEXT_NODE) {
    StringBuilder sb = new StringBuilder();
    for (Node currentSibling = xpathnode.getParentNode()
            .getFirstChild(); currentSibling != null; currentSibling = currentSibling.getNextSibling()) {
        if (currentSibling.getNodeType() == Node.TEXT_NODE) {
            sb.append(((Text) currentSibling).getData());
    return sb.toString();
} else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
    return xpathnode.getNodeValue();
} else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
    return xpathnode.getNodeValue();
return null;