Question

I have the following XSD complex types:

  <!-- Authentication type -->
  <xs:simpleType name="DatabaseAuthentication">
    <xs:restriction base="xs:string">
      <xs:enumeration id="Windows" value="Windows" />
      <xs:enumeration id="SQL" value="SQL" />
    </xs:restriction>
  </xs:simpleType>


<!-- Credentials -->
<xs:complexType name="Credentials">
  <xs:sequence>
    <xs:element name="Domain" minOccurs="0" maxOccurs="1" type="xs:string" />
    <xs:element name="Username" minOccurs="1" maxOccurs="1" type="xs:string" />
    <xs:element name="Password" minOccurs="1" maxOccurs="1" type="xs:string" />
  </xs:sequence>
  <xs:attribute name="Authentication" type="DatabaseAuthentication" use="required" />
</xs:complexType>

Sometime I need to work with the Credentials complex type but without the Authentication attribute. I would like to extend this complex type and instruct the XSD to skip that attribute. Something like this:

<xs:element name="CustomCredentials" minOccurs="1" maxOccurs="1">
  <xs:complexType>
    <xs:complexContent>
      <xs:extension base="Credentials">
       <!-- Here I would like to remove the Authentication attribute -->
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:element>
Was it helpful?

Solution

Extension always adds things, it cannot remove things.

The normal way to remove things is by restriction. But restriction can only remove things that were optional in the original (If type R is a restriction of type B, then every valid instance of R must also be a valid instance of B).

I think you need to define your existing Credentials type as an extension of some new type that does not include the Authentication attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top