public static Document parse(Reader reader,boolean validating,boolean namespaceAware,boolean allowDocTypeDeclaration) throws SAXException, IOException, ParserConfigurationException {
  DocumentBuilderFactory factory=FactorySupport.createDocumentBuilderFactory();
  factory.setNamespaceAware(namespaceAware);
  factory.setValidating(validating);
  setQuietly(factory,XMLConstants.FEATURE_SECURE_PROCESSING,true);
  setQuietly(factory,"http://apache.org/xml/features/disallow-doctype-decl",!allowDocTypeDeclaration);
  DocumentBuilder documentBuilder=factory.newDocumentBuilder();
  return documentBuilder.parse(new InputSource(reader));
}

public static Document parse ( Reader reader , boolean validating , boolean namespaceAware , boolean allowDocTypeDeclaration ) throws SAXException , IOException , ParserConfigurationException { DocumentBuilderFactory factory = FactorySupport . createDocumentBuilderFactory ( ) ; factory . setNamespaceAware ( namespaceAware ) ; factory . setValidating ( validating ) ; setQuietly ( factory , XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; setQuietly ( factory , "http://apache.org/xml/features/disallow-doctype-decl" , ! allowDocTypeDeclaration ) ; DocumentBuilder documentBuilder = factory . newDocumentBuilder ( ) ; return documentBuilder . parse ( new InputSource ( reader ) ) ; }
creates a documentbuilder and uses it to parse the xml text read from the given reader , allowing parser validation , namespace awareness and permission of doctype declarations to be controlled .
