xmlxsdrestriction

Do unmentioned element attributes in a complexContent xsd:restriction copy over from the parent type?


If an element in an xsd:restriction doesn’t have an attribute used by the matching element of the complex type the restriction is derived from, what is the calculated value of the attribute for the element in the restriction? Is it copied from the element it’s derived from? Is it the default?

Given the following schema:

<xs:complexType name="address">
  <xs:sequence>
    <xs:element name="street" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
  </xs:sequence>
</xs:complexType>

<xs:complexType name="USAddress">
  <xs:complexContent>
    <xs:restriction base="address">
      <xs:sequence>
        <xs:element name="street" type="xs:string" minOccurs="0" />
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

What is the calculated value of maxOccurs on the street element of USAddress?


Solution

  • I first assumed that you were asking about what attributes are permitted on an instance of the type address/USaddress, which had me a bit confused because the type doesn't define any attributes. But I guess you are actually asking about the value of maxOccurs on the restricted type. The answer (I'm fairly sure) is that it takes its default of 1.

    Reasoning:

    XSD 1.0 part 1 §5.4.2 says 5.4.2 The particle of the complex type definition itself must be a ·valid restriction· of the particle of the {content type} of the {base type definition} as defined in Particle Valid (Restriction) (§3.9.6).

    This is a constraint on two particles (schema components), not on their XML representation. So we have to form the two particles from their XML representations independently, and then compare them. The rules for forming a particle component for an element particle are in §3.3.2:

    {max occurs} unbounded, if the maxOccurs [attribute] equals unbounded, otherwise the ·actual value· of the maxOccurs [attribute], if present, otherwise 1.

    There is no suggestion that the {max occurs} property of the derived type involves looking at the corresponding particle from the base complex type; it only depends on the XML representation of the derived type.