public static void validateXMLSchema ( InputStream xsdStream , InputStream xmlStream ) throws IOException , SAXException { SchemaFactory factory = SchemaFactory . newInstance ( XMLConstants . W3C_XML_SCHEMA_NS_URI ) ; Schema schema = factory . newSchema ( new StreamSource ( xsdStream ) ) ; Validator validator = schema . newValidator ( ) ; validator . validate ( new StreamSource ( xmlStream ) ) ; }
Validate XML matches XSD . Stream - based method .