docBuilder.parse(new StringInputStream(contents));
source = new InputSource(new StringReader(contents)); docBuilder.parse(source);
  public boolean validateContents(String contents) throws XMLDBException {    try {      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();      factory.setNamespaceAware(true);      DocumentBuilder docBuilder = factory.newDocumentBuilder();      ValidationErrorHandler errorHandler = new ValidationErrorHandler();      docBuilder.setErrorHandler(errorHandler);      Document document = docBuilder.parse(new StringInputStream(contents));      Set namespaces = new TreeSet();      findNamespaces(document.getDocumentElement(), namespaces);      SchemaService schemaService = (SchemaService) getParentCollection().getService("SchemaService", "1.0");      ArrayList schemas = new ArrayList();      LOG.debug("Getting schemas for validation (" + namespaces.size() + "): ");      for (Iterator i = namespaces.iterator(); i.hasNext();) {        String namespaceURI = (String) i.next();        XMLResource resource = schemaService.getSchema(namespaceURI);        if (resource != null) {          schemas.add((String) resource.getContent());          LOG.info(namespaceURI);        } else          LOG.warn("No schema for target namespace " + namespaceURI + " found.");      }      factory.setValidating(true);      try {        factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);        InputSource[] schemaSources = new InputSource[schemas.size() + getTransientSchemas().size()];        int i;        for (i = 0; i < schemas.size(); i++)          schemaSources[i] = new InputSource(new StringReader((String) schemas.get(i)));        for (Iterator iter = getTransientSchemas().iterator(); iter.hasNext(); i++)          schemaSources[i] = new InputSource(new StringReader((String) iter.next()));        factory.setAttribute(JAXP_SCHEMA_SOURCE, schemaSources);      } catch (IllegalArgumentException e) {        throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Parser does not support JAXP 1.2", e);      }      docBuilder = factory.newDocumentBuilder();      docBuilder.setErrorHandler(errorHandler);      docBuilder.parse(new StringInputStream(contents));      if (errorHandler.getErrors().size() > 0)        throw errorHandler.toException();      return true;    } catch (ParserConfigurationException e) {      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Parser config error validating contents.", e);    } catch (SAXException e) {      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "SAX error reading contents.", e);    } catch (IOException e) {      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "IO error reading contents", e);    }  }