title: XML validation does not release the xml file
body: <p>I'm trying to validate an XML file against an XSD file in JAVA. My problem is not the validation itself, since this is working fine.
  My problem is, that the XMLfile is not released after the validation. If I'm trying to access the file afterwards, I get the error "The file is used by another resource".</p>
  
  <p>This error only happens, when the validation fails (an exception is trown from the validator.validate(xmlSource);)
  If the file is validated without problems, the file is released and can be accessed by others.</p>
  
  <p>Any idears?</p>
  
  <pre><code>public void validateXMLAgainstXSD(String xmlPath, String xsdPath) throws ParserException, IOException
    {
      Source xmlSource = null;
      File schemaFile = null;
      SchemaFactory schemaFactory = null;
      Schema schema = null;
      Validator validator = null;
      try 
      {
        schemaFile = new File(xsdPath);
        xmlSource = new StreamSource(new File(xmlPath));
        schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schema = schemaFactory.newSchema(schemaFile);
        validator = schema.newValidator();
        validator.validate(xmlSource);
      }
      catch (SAXException e)
      {
        //_log.error("ParsingDataFile: XML file could not be validated against XSD file: XML File=&lt;", xmlFile.getAbsolutePath(), "&gt; XSD file=&lt;", xsdFile.getAbsolutePath(), "&gt;. Exception=&lt;", e, "&gt;");
        xmlSource = null;
        schemaFile = null;
        schemaFactory = null;
        schema = null;
        validator.reset();
        validator = null;      
        //throw new ParserException(-1, ParserException.ERROR_CODE_XML_NOT_VALID, e);
      }
    }
  </code></pre>