public static Document stringToDoc ( String str ) throws IOException { if ( StringUtils . isNotEmpty ( str ) ) { try ( Reader reader = new StringReader ( str ) ) { DocumentBuilder db = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) ; Document doc = db . parse ( new InputSource ( reader ) ) ; return doc ; } catch ( Exception ex ) { log . debug ( "String: {}" , str ) ; throw new IOException ( String . format ( "Error converting from string to doc %s" , ex . getMessage ( ) ) ) ; } } else { throw new IOException ( "Error - could not convert empty string to doc" ) ; } }
Converts string representation of XML into Document