title: Validate XML Against XSD
body: <p>Looking for some confirmation that the below is the most efficient Java solution to validate a XML String against a schema.  Any other ways which are more efficient memory or performance wise?</p>
  
  <pre><code>private boolean isXMLValid(String XSDPath, String XML) {
          final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          try {
              final Schema schema = factory.newSchema(new File(XSDPath));
              final Validator validator = schema.newValidator();
              validator.validate(new StreamSource(new ByteArrayInputStream(XML.getBytes())));
          } catch (IOException | SAXException e) {
              System.out.println("Exception: " + e.getMessage());
              return false;
          }
          return true;
      }
  </code></pre>