Java XML Child Element Text getChildTextNodeValue(Node node)

Here you can find the source of getChildTextNodeValue(Node node)

Description

Returns value of single child text node or null.

License

Open Source License

Declaration

public static String getChildTextNodeValue(Node node) 

Method Source Code

//package com.java2s;
/**/*from w  ww  .j  a v a2  s .  c o m*/
 * This file is part of SIMPL4(http://simpl4.org).
 *
 *    Copyright [2014] [Manfred Sattler] <manfred@ms123.org>
 *
 * SIMPL4 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, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SIMPL4 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with SIMPL4.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Node;

public class Main {
    /**
     * Returns value of single child text node or <code>null</code>.
     */
    public static String getChildTextNodeValue(Node node) {
        if (node.getChildNodes().getLength() != 1) {
            return null;
        }
        Node item0 = node.getChildNodes().item(0);
        if (item0.getNodeType() != Node.TEXT_NODE) {
            return null;
        }
        return item0.getNodeValue();
    }
}

Related

  1. getChildTextContent(Element elemenet, String childElemenetName)
  2. getChildTextContent(Element element, String childTagName)
  3. getChildTextList(Element elem, String childTagName)
  4. getChildTextNode(Element el)
  5. getChildTextNodes(Element parent)
  6. getChildTextNodeValues(Node theNode)