public static String outputNestedList ( NestedList nl , int depth ) { String result = "" ; if ( nl == null ) { return result ; // If null return empty string } for ( int i = 0 ; i < depth ; i ++ ) { result += " " ; // insert indentation according to depth } if ( nl . getClass ( ) == NestedListElement . class ) { // If it is a NestedListElement, // we reached a leaf, return its contents result += nl . getText ( ) ; } else { result += "---" ; // If it is not a NestedListElement, it is a NestedListContainer // print out all its childs, increment depth for ( NestedList nl2 : ( ( NestedListContainer ) nl ) . getNestedLists ( ) ) { result += "\n" + outputNestedList ( nl2 , depth + 1 ) ; } } return result ; }
Returns String with all elements of a NestedList