Java XPath Get getNodeText(XPath xpath, String xp, Node n)

Here you can find the source of getNodeText(XPath xpath, String xp, Node n)

Description

Return text content of a node, or null if it has none.

License

Open Source License

Parameter

Parameter Description
xpath XPath engine
xp xpath to the node
n context node

Exception

Parameter Description

Return

text content of the node

Declaration

public static String getNodeText(XPath xpath, String xp, Node n)
        throws javax.xml.xpath.XPathExpressionException 

Method Source Code


//package com.java2s;
/*//w  w  w . j  a  v  a 2  s.c  om
 * Copyright (C) 2015, The Max Planck Institute for
 * Psycholinguistics.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * A copy of the GNU General Public License is included in the file
 * LICENSE-gpl-3.0.txt. If that file is missing, see
 * <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Node;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;

public class Main {
    /** 
     * Return text content of a node, or null if it has none. 
     * 
     * @param xpath XPath engine
     * @param xp xpath to the node
     * @param n context node
     * @return text content of the node
     * @throws javax.xml.xpath.XPathExpressionException something is wrong with the xpath
     */
    public static String getNodeText(XPath xpath, String xp, Node n)
            throws javax.xml.xpath.XPathExpressionException {
        Node p = (Node) xpath.evaluate(xp, n, XPathConstants.NODE);
        if (p == null)
            return null;
        String s = p.getNodeValue();
        return (s == null) ? null : s.trim();
    }
}

Related

  1. getNodes(Node node, String expStr)
  2. getNodesByPath(String path, Element localElement, Document doc)
  3. getNodesByXPath(Document doc, XPathExpression expr)
  4. getNodesByXPath(Element parent, String name)
  5. getNodesListXpathNode(final String xPath, final Node node)
  6. getNodeTextByXPath(Document doc, String xpath)
  7. getNogeList(String path, Node node)
  8. getORSVersion()
  9. getProcessIdFromBpmn(final String bpmn)