So I\'m writing a new XSD and I\'ve come across a little issue. Now I\'ll admit I\'m not the best with these, but I would have thought what I have done should have worked bu
See @IanRoberts fine suggestion in the comments regarding asserting that no grandchild elements exist under the children of extraInfo
.
If you want more control over the type of the extraInfo
child elements, you'll have to specify their names a priori.
Attributes
Or, why not leverage the fact that attribute values already are constrained not to have subelements and use xsd:anyAttribute
instead:
<xsd:element name="extraInfo">
<xsd:complexType>
<xsd:anyAttribute processContents="skip" />
</xsd:complexType>
</xsd:element>
Users could then add extraInfo
along these lines:
<extraInfo
logoUrl="http://www.google.com/logo.png"
cssUrl="http://www.google.com/main.css"/>
and
<extraInfo
headerText="Hello World"
footerText="Goodbye World"/>
which would be natural given that you wish to allow only string values.
Elements (update per OP question in comments)
If the max of 42 constraint is important to you, you could go meta with a structure such as
<extraInfo>
<item name="logoUrl" value="http://www.google.com/logo.png"/>
<item name="cssUrl" value="http://www.google.com/main.css"/>
</extraInfo>
Then you could restrict the number of item
elements trivially in XSD 1.0 via @maxOccurs
.