What I'm looking to be able to create is one XSD which would validate both of the following:
<parent>
<mother>
<name>
<firstname>foo</firstname>
<surname> bar </surname>
<maidenname>rab</maidenname>
</name>
</mother>
</parent>
and
<parent>
<father>
<name>
<firstname>foo</firstname>
<surname> bar </surname>
</name>
</father>
</parent>
I ideally want to be able to use the same element name but have different requirements for it based on the parent attribute. What I've tried so far is:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="firstname">
<xs:complexType mixed="true" />
</xs:element>
<xs:element name="maidenname">
<xs:complexType mixed="true" />
</xs:element>
<xs:element name="mother">
<xs:complexType>
<xs:sequence>
<xs:element ref="name" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="father">
<xs:complexType>
<xs:sequence>
<xs:element ref="name" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="name">
<xs:complexType>
<xs:all>
<xs:element ref="firstname" />
<xs:element ref="surname" />
<xs:element ref="maidenname" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="parent">
<xs:complexType>
<xs:choice>
<xs:element ref="mother"/>
<xs:element ref="father"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="surname">
<xs:complexType mixed="true" />
</xs:element>
</xs:schema>