Example usage for org.w3c.dom Element getFirstChild

List of usage examples for org.w3c.dom Element getFirstChild

Introduction

In this page you can find the example usage for org.w3c.dom Element getFirstChild.

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:Main.java

public static String getElementFirstText(Element ele) {
    Node n = ele.getFirstChild();
    if (n instanceof Text) {
        return ((Text) n).getNodeValue();
    } else {//from  ww w. j  av a  2s .  co m
        return null;
    }
}

From source file:Main.java

public static String getCharacterDataFromElement(Element e) {
    Node child = e.getFirstChild();
    if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        return cd.getData();
    }//from   www . ja  v  a2 s  .c o  m
    return "?";
}

From source file:Main.java

public static Element GetFirstElementChild(Element tag) {
    Node n = tag.getFirstChild();
    while (n.getNodeType() != Node.ELEMENT_NODE) {
        n = n.getNextSibling();/*from www. j a  v  a 2  s  .  c o m*/
    }
    Element e = (Element) n;
    return e;
}

From source file:Main.java

private static String getTextValue(Element ele, String tagName) {
    String textVal = null;//from   ww w .ja  v a 2s .c o m
    NodeList nl = ele.getElementsByTagName(tagName);
    if (nl != null && nl.getLength() > 0) {
        Element el = (Element) nl.item(0);
        textVal = el.getFirstChild().getNodeValue();
    }
    return textVal;
}

From source file:Main.java

public static Element findFirstChildElement(Element parent) {
    org.w3c.dom.Node ret = parent.getFirstChild();
    while (ret != null && (!(ret instanceof Element))) {
        ret = ret.getNextSibling();//  ww w  .  ja va  2s .c o  m
    }
    return (Element) ret;
}

From source file:Main.java

/**
 * Gets the first child element of an element
 *
 * @param element the parent// www .  j a  v  a2  s  .com
 * @return the first child element or null if there isn't one
 */
public static Element getFirstChildElement(Element element) {
    Node child = element.getFirstChild();
    while (child != null && child.getNodeType() != Node.ELEMENT_NODE)
        child = child.getNextSibling();

    return (Element) child;
}

From source file:Main.java

/**
 * Returns first DOM node of type element contained within given element.
 *  //from  w ww.j a  va 2s . c  o  m
 * @param elem element
 */
public static Element getContainedElement(Element elem) {
    Node n = elem.getFirstChild();
    while (n != null) {
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            Element e = (Element) n;
            return e;
        }
        n = n.getNextSibling();
    }
    return null;
}

From source file:Main.java

public static Element getFirstChildByTagName(Element elem, String name) {
    for (Node child = elem.getFirstChild(); child != null; child = child.getNextSibling())
        if (child instanceof Element && name.equals(child.getNodeName()))
            return (Element) child;
    return null;//from   w w  w .java 2s .c  o  m
}

From source file:Main.java

/**
 * Returns the first child element, or null if none exists.
 * @param element/*from ww  w  .j av a 2 s  . c  o m*/
 * @return Element
 */
public static Element getFirstChildElement(Element element) {
    for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
        if (node instanceof Element) {
            return (Element) node;
        }
    }

    return null;
}

From source file:Main.java

public static Element findChildElement(Element parent) {
    for (org.w3c.dom.Node node = parent.getFirstChild(); node != null; node = node.getNextSibling()) {
        if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
            return (Element) node;
        }//  w  w  w . j av a 2s  .  c om
    }
    return null;
}