@ SuppressWarnings ( "unchecked" ) private String getFilteredXml ( Document document , String xpathExpression ) { logger . entering ( new Object [ ] { document , xpathExpression } ) ; List < Node > nodes = ( List < Node > ) document . selectNodes ( xpathExpression ) ; StringBuilder newDocument = new StringBuilder ( document . asXML ( ) . length ( ) ) ; newDocument . append ( "<root>" ) ; for ( Node n : nodes ) { newDocument . append ( n . asXML ( ) ) ; } newDocument . append ( "</root>" ) ; logger . exiting ( newDocument ) ; return newDocument . toString ( ) ; }
Generates an XML string containing only the nodes filtered by the XPath expression .