title: Denormalize XSD
body: <p>I need to denormalize an XML schema to generate documentation for the people that will create documents that conform to the schema. The users have no knowledge of XSD and will most likely never learn. The tools I've seen are able to generate documentation for fellow XSD developers, but my users are not interested in the details of how the schema is constructed, they only want to know what they can and must do to create valid documents.</p>
  
  <p>So, I'm looking for a way to resolve all includes and references in an XML schema and generate a denormalized version that I can use to (in turn) generate user documentation.</p>
  
  <p>I´ve started to do some of this using XSLT, but a proven tool would be helpful. I also tried XSD4J, but it apparently strips all annotations that I need to generate something useful.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>What I want is to resolve all references and make all definitions inline. For example, the following schema:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:element name="AAAA" type="myComplexType"/&gt;
    &lt;xs:complexType name="myComplexType"&gt;
      &lt;xs:all&gt;
        &lt;xs:element name="BBBB"&gt;
          &lt;xs:complexType&gt;
            &lt;xs:attribute name="cccc" type="mySimpleType"/&gt;
          &lt;/xs:complexType&gt;
        &lt;/xs:element&gt;
      &lt;/xs:all&gt;
    &lt;/xs:complexType&gt;
    &lt;xs:simpleType name="mySimpleType"&gt;
      &lt;xs:restriction base="xs:string"&gt;
        &lt;xs:minLength value="1"/&gt;
      &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>should be denormalized into:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:element name="AAAA"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:all&gt;
          &lt;xs:element name="BBBB"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:attribute name="cccc"&gt;
                &lt;xs:simpleType&gt;
                  &lt;xs:restriction base="xs:string"&gt;
                    &lt;xs:minLength value="1"/&gt;
                  &lt;/xs:restriction&gt;
                &lt;/xs:simpleType&gt;
              &lt;/xs:attribute&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:all&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Annotations for element and attribute definitions also need to survive the transformation.</p>