public static Document parseXmlString(String _xmlStr, boolean _validating, boolean _namespaceAware) throws IOException {

        DocumentBuilderFactory dbFac = DocumentBuilderFactory.newInstance();
        dbFac.setNamespaceAware(_namespaceAware);
        dbFac.setValidating(_validating);

        try {
            return dbFac.newDocumentBuilder().parse(new ByteArrayInputStream(_xmlStr.getBytes(StandardCharsets.UTF_8)));

        } catch (IOException _ex) {
            throw _ex;
        } catch (Exception _ex) {
            throw new IOException("Failed to parse " + StringUtil.abbreviate(_xmlStr, 500), _ex);
        }

    }
public static Document parseXmlString ( String _xmlStr , boolean _validating , boolean _namespaceAware ) throws IOException { DocumentBuilderFactory dbFac = DocumentBuilderFactory . newInstance ( ) ; dbFac . setNamespaceAware ( _namespaceAware ) ; dbFac . setValidating ( _validating ) ; try { return dbFac . newDocumentBuilder ( ) . parse ( new ByteArrayInputStream ( _xmlStr . getBytes ( StandardCharsets . UTF_8 ) ) ) ; } catch ( IOException _ex ) { throw _ex ; } catch ( Exception _ex ) { throw new IOException ( "Failed to parse " + StringUtil . abbreviate ( _xmlStr , 500 ) , _ex ) ; } }
Read the given string as XML document.

@param _xmlStr xml string
@param _validating boolean
@param _namespaceAware boolean
@return {@link org.w3c.dom.Document}
@throws IOException on error