private TEIValidator.Errors extractDocumentHeaders(Document doc) throws LaudatioException, IOException, SAXException
  {
    TEIValidator validator = 
      documentSchemeURL == null ? new TEIDocumentValidator(): new FromURLValidator(documentSchemeURL);
    
    File documentDir = new File(outputDirectory, "DocumentHeader");
    if (!documentDir.exists() && !documentDir.mkdir())
    {
      throw new LaudatioException(messages.getString(
        "COULD NOT CREATE DIRECTORY")
        + documentDir.getAbsolutePath());
    }
    
    Element documentRoot = Preconditions.checkNotNull(doc.getRootElement()
      .getChild("teiCorpus", null));
    
    
    for(Element docHeader : documentRoot.getChildren("teiHeader", null))
    {
      Preconditions.checkState("DocumentHeader".equals(docHeader.getAttributeValue("type")));
      
      // create the subtree for the global corpus header
      Namespace teiNS = Namespace.getNamespace(
        "http://www.tei-c.org/ns/1.0");
      Element tei = new Element("TEI", teiNS);
      tei.addContent(docHeader.clone());
      Document newDoc = new Document(tei);
      
      if(documentSchemeURL == null)
      {
        newDoc.addContent(0, new ProcessingInstruction("xml-model", 
          "href=\"" + TEIDocumentValidator.DEFAULT_SCHEME_URL + "\""));
      }
      else
      {
        newDoc.addContent(0, new ProcessingInstruction("xml-model", 
          "href=\"" + documentSchemeURL + "\""));
      }
      
      // we need to append an empty "text" element after the header
      Element text = new Element("text", teiNS);
      text.setText("");
      tei.addContent(text);
      
      Element fileDesc = Preconditions.checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null));
      
      String outName = UUID.randomUUID().toString();
      
      String id = fileDesc.getAttributeValue("id", Namespace.XML_NAMESPACE);
      if(id != null)
      {
        outName = id;
      }
      else
      {
        Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null));
        
        String title = titleStmt.getChildText("title", null);
        if(title != null)
        {
          outName = title;
        }
      }
      
      
      File outputFile = new File(documentDir, outName + ".xml");
      XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
      xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
      log.info(messages.getString("WRITTEN DOCUMENT HEADER"), outputFile.getPath());
      
      
      validator.validate(outputFile);
      
    }
    return validator.getErrors();
  }