title: How to extend an xml-schema from another xml-schema?
body: <p>I have an xml document that looks something like below (resources.xml), with a corresponding xml-schema (resources.xsd). This xml document is manually maintained (i.e adding/removing/editing resource elements). In total there are maybe 500-1000 resource elements. Each resource can be of either variantX or variantY (in "real life", there are a few more variants). </p>
  
  <p>I would like to split up the xml document into several xml documents. One xml document for each variant (X and Y in this case), with a corresponding new xml-schemas. The xml schemas for each variant, should extend the original schema and only add a "hardcoded" (fixed?) value for it's "variant" attribute. </p>
  
  <p>Reason: To avoid repeating the "variant" attribute within each resource element.</p>
  
  <p>Is this possible? What would the xml-schemas for each variant look like? What changes needs to be done in resources.xsd? </p>
  
  <p>Any other suggestions are also welcomed :)</p>
  
  <h2>resources.xml</h2>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;resources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="resources.xsd"&gt;
          &lt;resource name="res00" variant="X" &gt;
              &lt;property name="propA" value="..." /&gt;
              &lt;property name="propB" value="..." /&gt;
          &lt;/resource&gt;
          &lt;resource name="res01" variant="X" &gt;
              &lt;property name="propA" value="..." /&gt;
              &lt;property name="propB" value="..." /&gt;
          &lt;/resource&gt;
          &lt;resource name="res02" variant="Y" &gt;
              &lt;property name="propA" value="..." /&gt;
              &lt;property name="propB" value="..." /&gt;
          &lt;/resource&gt;
          &lt;resource name="res03" variant="Y" &gt;
              &lt;property name="propA" value="..." /&gt;
              &lt;property name="propB" value="..." /&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;
  </code></pre>
  
  <h2>resources.xsd</h2>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:rb="http://example.org/resourcebase"&gt;
  
      &lt;xs:complexType name="property"&gt;
          &lt;xs:attribute name="name" type="xs:string" /&gt;
          &lt;xs:attribute name="value" type="xs:string" /&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="resource"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" /&gt;
          &lt;/xs:sequence&gt;
          &lt;xs:attribute name="name" type="xs:string" use="required" /&gt;
          &lt;xs:attribute name="variant" type="xs:string" use="required" /&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:element name="resources"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="resource" type="resource" minOccurs="0" maxOccurs="unbounded" /&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Here's how I picture this. One xml document for variant=X, which referrers to resourcesX.xsd. No need to add the "variant" attribute, as it is added by the referred resourcesX.xsd.</p>
  
  <h2>resourcesX.xml</h2>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;resources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="resourceX.xsd"&gt;
          &lt;resource name="res00" &gt;
              &lt;property name="propA" value="..." /&gt;
              &lt;property name="propB" value="..." /&gt;
          &lt;/resource&gt;
          &lt;resource name="res01" &gt;
              &lt;property name="propA" value="..." /&gt;
              &lt;property name="propB" value="..." /&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;
  </code></pre>
  
  <p>Another xml document for variant=Y, which referrers to resourcesY.xsd. No need to add the "variant" attribute, as it is added by the referred resourcesY.xsd.</p>
  
  <h2>resourcesY.xml</h2>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;resources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="resourceY.xsd"&gt;
          &lt;resource name="res02" &gt;
              &lt;property name="propA" value="..." /&gt;
              &lt;property name="propB" value="..." /&gt;
          &lt;/resource&gt;
          &lt;resource name="res03" &gt;
              &lt;property name="propA" value="..." /&gt;
              &lt;property name="propB" value="..." /&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;
  </code></pre>
  
  <p>Can resourceX.xsd and resourceY.xsd extend the resources.xsd? If so, what would they look like? any changes needed to be made in resources.xsd?</p>
  
  <p>Thanks!
  /Alex</p>