public static Element [ ] getChildren ( Element root , String name ) { if ( null == root ) { return new Element [ 0 ] ; } NodeList list = root . getElementsByTagName ( name ) ; int n = list . getLength ( ) ; ArrayList < Element > result = new ArrayList < Element > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Node item = list . item ( i ) ; if ( item instanceof Element ) { result . add ( ( Element ) item ) ; } } Element [ ] retval = new Element [ result . size ( ) ] ; result . toArray ( retval ) ; return retval ; }
Return all children matching the supplied element name .