code: public String xsdToString(final XmlSchema xsd, final String xsltFileName)
              throws XsdGenerationException {
  
          if (_log.isDebugEnabled()) {
              StringWriter writer = new StringWriter();
              xsd.write(writer);
              _log.debug("6. Writing XML Schema: {}", writer.toString());
          }
  
          String errorMessage = "Customizing XML Schema failed.";
          try {
              TransformerFactory tFactory = TransformerFactory.newInstance();
              try {
                  tFactory.setAttribute("indent-number", "4");
              } catch (IllegalArgumentException e) {
                  _log.debug("Unable to set indent-number on transfomer factory",
                          e);
              }
              StringWriter writer = new StringWriter();
              Source source = new DOMSource(xsd.getAllSchemas()[0]);
              Result result = new StreamResult(writer);
              Transformer transformer;
              if (xsltFileName == null || xsltFileName.trim().length() == 0) {
                  transformer = tFactory.newTransformer();
              } else {
                  Source xsltSource = new StreamSource(new File(xsltFileName));
                  transformer = tFactory.newTransformer(xsltSource);
              }
              transformer.setOutputProperty(OutputKeys.ENCODING, getConfig()
                      .getXsdEncoding());
              transformer.setOutputProperty(OutputKeys.INDENT, "yes");
              transformer
                      .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
              transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
  
              transformer.transform(source, result);
              writer.flush();
  
              return writer.toString();
          } catch (TransformerConfigurationException e) {
              _log.error(errorMessage, e);
              throw new XsdGenerationException(e);
          } catch (TransformerFactoryConfigurationError e) {
              _log.error(errorMessage, e);
              throw new XsdGenerationException(e);
          } catch (TransformerException e) {
              _log.error(errorMessage, e);
              throw new XsdGenerationException(e);
          }
      }
docs: Serialize the XML Schema to a string.
  <p/>
  If we are provided with an XSLT customization file then we transform the
  XMLSchema.
  
  @param xsd the XML Schema before customization
  @param xsltFileName an optional xslt to apply on the XML Schema
  @return a string serialization of the customized XML Schema
  @throws XsdGenerationException if customization fails