I'm trying to create a XSD to validate this kind of XML:
<Upload>
<DocumentData>
<docid>123</docid>
<domain>PNI</domain>
<expiry_date>20150101101010</expiry_date>
<name>orçamento.xlsx</name>
<type>orçamento</type>
<user>nmsanto</user>
<file>fdsfjdflkdsçlfd</file>
<comments></comments>
</DocumentData>
<DocumentAttributes>
<projectid>123</projectid>
<objectid>1</objectid>
<keyword1>Nuno</keyword1>
<keyword1>Rua xpto</keyword1>
<keyword2>1223-123</keyword2>
<keyword3>Lisboa</keyword3>
</DocumentAttributes>
</Upload>
The XML must always have the element Upload with the elements DocumentData and DocumentAttributes. In DocumentData the elements domain, name, type, user and file are mandatory and can only show up one time, while the others are optional. The most difficulty I'm having is with the DocumentAttributes element. There has to be at least one of either projectid or objectid, keyword1-keyword6 are optional and there can be 4 more optional elements with any name.
So far the XSD I have is this one:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="Upload">
<xs:complexType>
<xs:all>
<xs:element name="DocumentData">
<xs:complexType>
<xs:all>
<xs:element name="docid" type="xs:string" minOccurs="0" />
<xs:element name="domain" type="xs:string" />
<xs:element name="versao" type="xs:integer" minOccurs="0" />
<xs:element name="name" type="xs:string" />
<xs:element name="expiry_date" type="xs:string" />
<xs:element name="type" type="xs:string" />
<xs:element name="user" type="xs:string" />
<xs:element name="file" type="xs:string" />
<xs:element name="comments" type="xs:string"
minOccurs="0" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="DocumentAttributes">
<xs:complexType>
<xs:all>
<xs:element type="xs:string" minOccurs="0" />
<xs:element type="xs:string" minOccurs="0" />
<xs:element type="xs:string" minOccurs="0" />
<xs:element type="xs:string" minOccurs="0" />
<xs:element name="keyword1" type="xs:string"
minOccurs="0" />
<xs:element name="keyword2" type="xs:string"
minOccurs="0" />
<xs:element name="keyword3" type="xs:string"
minOccurs="0" />
<xs:element name="keyword4" type="xs:string"
minOccurs="0" />
<xs:element name="keyword5" type="xs:string"
minOccurs="0" />
<xs:element name="keyword6" type="xs:string"
minOccurs="0" />
<xs:element name="usetype" abstract="true" />
<xs:element name="projectid" substitutionGroup="usetype" />
<xs:element name="objectid" substitutionGroup="usetype" />
</xs:all>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
I have tried putting a choice element inside the all element to validate the objectid/projectid but I've learned that it isn't possible to do so. How would I go about validating that?