Name

childNodes: NodeList

Synopsis

Returns a NodeList containing a reference to every child of this Node.

Java binding

public NodeList getChildNodes( );

Java example

// List the text contents of an element
NodeList nlChildren = elem.getChildNodes( );
Node ndChild;
     
for (int iNode = 0; iNode < nlChildren.getLength( ); iNode++) {
    ndChild = nlChildren.item(iNode);
     
    if (ndChild.getNodeType( ) =  = Node.TEXT_NODE) {
        System.out.println(ndChild.getNodeValue( ));
    }
}

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.