DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(new LocalEntityResolver());
//Turn on line below when XML DTD validation will pass.
builder.setErrorHandler(new ReThrowingErrorHandler());
return builder.parse(new ByteArrayInputStream(xml.getBytes()));
}