Java XML Child Node Get getChildNodeValue(Element node, String tagName)

Here you can find the source of getChildNodeValue(Element node, String tagName)

Description

get Child Node Value

License

Open Source License

Declaration

private static String getChildNodeValue(Element node, String tagName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013,2014 Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:// w  w w .  j  av a  2  s  .c  o  m
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    private static String getChildNodeValue(Element node, String tagName) {
        NodeList nodes = node.getElementsByTagName(tagName);
        if (nodes.getLength() > 0) {
            return nodes.item(0).getTextContent().trim();
        }
        return null;
    }
}

Related

  1. getChildNodesWithName(Node node, String name)
  2. getChildNodeText(Element element, String nodeTagName)
  3. getChildNodeText(Node root, String childName)
  4. getChildNodeTextContent(Node parentNode, String childElementName)
  5. getChildNodeTextContents(Node node, String name)
  6. getChildNodeValue(Element root, String childNodeName, String defaultValue)
  7. getChildNodeValue(Node node, String elementName)
  8. getChildNodeValue(Node root, String childName, boolean emptyStringOnMissingChild)
  9. getChildNodeValue(String childNodeName, Node n)