Java XML First Child Element getFirstChildText(Node aNode)

Here you can find the source of getFirstChildText(Node aNode)

Description

get First Child Text

License

Open Source License

Parameter

Parameter Description
aNode a parameter

Declaration

public static Node getFirstChildText(Node aNode) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 www.isandlatech.com (www.isandlatech.com)
 * All rights reserved. This program and the accompanying materials
 * are 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  a  va  2 s  .  co m
 *    ogattaz (isandlaTech) - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    /**
     * @param aNode
     * @return
     */
    public static Node getFirstChildText(Node aNode) {

        if (aNode == null) {
            return null;
        }
        Node wNode = aNode.getFirstChild();
        if (wNode == null || wNode.getNodeType() == Node.TEXT_NODE) {
            return wNode;
        } else {
            return getFirstSiblingElmt(wNode);
        }
    }

    /**
     * @param aNode
     * @return
     */
    public static Element getFirstSiblingElmt(Node aNode) {

        if (aNode == null) {
            return null;
        }
        Node wNode = aNode.getNextSibling();
        while (wNode != null && wNode.getNodeType() != Node.ELEMENT_NODE) {
            wNode = wNode.getNextSibling();
        }
        return (Element) wNode;
    }
}

Related

  1. getFirstChildNodeWithName(String nodeName, Node parentNode)
  2. getFirstChildOfTagName(Element elem, String name)
  3. getFirstChildOfType(final Element elParent, final String childTag)
  4. getFirstChildTag(Element el, String tag)
  5. getFirstChildText(@Nullable final Node aStartNode)
  6. getFirstChildText(Node parent)
  7. getFirstChildTextByTagName(Element element, String tagName)
  8. getFirstChildTextContent(Node node)
  9. getFirstChildTextNodeValue(Node node)