Reputation: 26129
I have a complexType User:
<xs:complexType name="User">
<xs:all>
<xs:element name="id" type="xs:positiveInteger" minOccurs="1" maxOccurs="1" />
<xs:element name="email" type="email" minOccurs="1" maxOccurs="1" />
<xs:element name="password" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1" />
</xs:all>
</xs:complexType>
and I have to use it with constraints on elements minOccurs and maxOccurs.
For example by login I need the User with email and password elements only, so I need any other elements (id,name) with maxOccurs=0 and minOccurs=0.
<Auth:login>
<User>
<email>[email protected]</email>
<password>mypass</password>
</User>
</Auth:login>
Is it possible to validate the XML above with a restricted complexType of User?
Upvotes: 0
Views: 355
Reputation: 26129
It's possible with assertions (in xsd 1.1), but I think php has only xsd 1.0 support :S
I found here some help. I can put my sub elements into groups, and concatenate the actually needed groups.
Upvotes: 0
Reputation: 163262
No: type R can only restrict type B if all instances of R are valid instances of B. Since B requires id and name to be present, a type that requires them (or even permits them) to be absent is not a valid restriction of B.
Upvotes: 1