private static String outerHtml ( List < Element > elements ) { switch ( elements . size ( ) ) { case 0 : return "" ; case 1 : return elements . get ( 0 ) . outerHtml ( ) ; default : { // more than one element // wrap into <div> which we will remove afterwards Element root = new Element ( Tag . valueOf ( "div" ) , "" ) ; for ( Element elem : elements ) { root . appendChild ( elem ) ; } return root . html ( ) ; } } }
Outputs the list of partition root elements to HTML .