Here you can find the source of getNodeText(XPath xpath, String xp, Node n)
Parameter | Description |
---|---|
xpath | XPath engine |
xp | xpath to the node |
n | context node |
Parameter | Description |
---|
public static String getNodeText(XPath xpath, String xp, Node n) throws javax.xml.xpath.XPathExpressionException
//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(); } }