public static String extractXML ( Node node , int start , int length ) { ExtractHandler handler = null ; try { handler = new ExtractHandler ( start , length ) ; Transformer xformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; xformer . transform ( new DOMSource ( node ) , new SAXResult ( handler ) ) ; return handler . getResult ( ) ; } catch ( Throwable t ) { if ( handler != null && handler . isFinished ( ) ) { return handler . getResult ( ) ; } else { throw new RuntimeException ( "Failed to extract XML" , t ) ; } } }
Extracts a well - formed XML fragment from the given DOM tree .