Java XML Child Element Text getChildText(Node node)

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

Description

Returns the value of the first child node of the given node, and asserts that the child node is a Text node.

License

Open Source License

Parameter

Parameter Description
node a node containing a single Text child node

Return

the value of the child Text node

Declaration

public static String getChildText(Node node) 

Method Source Code

//package com.java2s;
/*// www .  j  a  va 2  s . co m
 * Misc-Utils - Miscellaneous Utility Classes
 * Copyright (C) 2007 Newisys, Inc. or its licensors, as applicable.
 * Java is a registered trademark of Sun Microsystems, Inc. in the U.S. or
 * other countries.
 *
 * Licensed under the Open Software License version 3.0 (the "License"); you
 * may not use this file except in compliance with the License. You should
 * have received a copy of the License along with this software; if not, you
 * may obtain a copy of the License at
 *
 * http://opensource.org/licenses/osl-3.0.php
 *
 * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

import org.w3c.dom.Node;

public class Main {
    /**
    * Returns the value of the first child node of the given node, and asserts
    * that the child node is a Text node.
    * 
    * @param node a node containing a single Text child node
    * @return the value of the child Text node
    */
    public static String getChildText(Node node) {
        Node child = node.getFirstChild();
        assert (child.getNodeType() == Node.TEXT_NODE);
        return child.getNodeValue();
    }
}

Related

  1. getChildText(final Element element, final String tagName)
  2. getChildText(final Element element, final String tagName)
  3. getChildText(final Element parentElem, final String childName)
  4. getChildText(final Node node)
  5. getChildText(final Node node)
  6. getChildText(Node node)
  7. getChildText(Node node)
  8. getChildText(Node parent, String childName)
  9. getChildTextAsBoolean(Element parent, String childName, boolean defValue)