Java XML validation does not work when schema comes from classpath
问题 I am validating XML documents against a schema. Some more complex documents/schemas always fail when trying to validate them using this code: DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); dbfac.setNamespaceAware(true); dbfac.setIgnoringElementContentWhitespace(true); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.parse("sampleResponse.xml"); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);