Java Utililty Methods XML Child Get

List of utility methods to do XML Child Get

Description

The list of methods to do XML Child Get are organized into topic(s).

Method

ElementgetChild(Node node, String name, String attrName, String attrValue)
Gets a child element of a node by name and attribute value.
NodeList children = node.getChildNodes();
int numChildren = children.getLength();
for (int i = 0; i < numChildren; i++) {
    Node child = children.item(i);
    if (child.getNodeType() != Node.ELEMENT_NODE)
        continue;
    if (child.getNodeName().equals(name)) {
        Element el = (Element) child;
...
NodegetChild(Node parent, String name)
Get the first element child.
if (parent == null)
    return null;
Node first = parent.getFirstChild();
if (first == null)
    return null;
for (Node node = first; node != null; node = node.getNextSibling()) {
    if (node.getNodeType() != Node.ELEMENT_NODE)
        continue;
...
NodegetChild(Node parent, String name)
get Child
if (parent == null) {
    return null;
Node first = parent.getFirstChild();
if (first == null) {
    return null;
for (Node node = first; node != null; node = node.getNextSibling()) {
...
ListgetChildElements(Element e)
get Child Elements
List<Element> r = new ArrayList<Element>();
NodeList l = e.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
    Node n = l.item(i);
    if (n.getNodeType() == Node.ELEMENT_NODE)
        r.add((Element) n);
return r;
...
ListgetChildElements(Element e)
Create a new list containing only the child nodes of e of type Element .
List<Element> ret = new ArrayList<Element>();
NodeList children = e.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    Node child = children.item(i);
    if (child.getNodeType() == Node.ELEMENT_NODE) {
        ret.add((Element) child);
return ret;
ListgetChildElements(Element e, String tag)
get Child Elements
NodeList children = e.getElementsByTagName(tag);
if (children == null || children.getLength() == 0)
    return null;
List<Element> result = new ArrayList<Element>();
for (int index = 0; index < children.getLength(); index++) {
    Node n = children.item(index);
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        result.add((Element) n);
...
VectorgetChildElements(Element el)
Gets a list of the given element's child DOM elements.
return getChildElements(null, el);
ListgetChildElements(Element ele)
Retrieve all child elements of the given DOM element
Assert.notNull(ele, "Element must not be null");
NodeList nl = ele.getChildNodes();
List<Element> childEles = new ArrayList<Element>();
for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node instanceof Element) {
        childEles.add((Element) node);
return childEles;
ListgetChildElements(Element ele)
get Child Elements
NodeList nl = ele.getChildNodes();
List<Element> childEles = new LinkedList<Element>();
for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node instanceof Element) {
        childEles.add((Element) node);
return childEles;
ListgetChildElements(Element ele)
Get all child elements
List<Element> list = new ArrayList<>();
NodeList childNodes = ele.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
    if (childNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
        list.add((Element) childNodes.item(i));
return list;
...