When using XML Schema to declare that a complexType
has just one child element, all the below three approaches achieve the goal:
<xs:complexType> <xs:sequence> <xs:element ref="somevalue"/> </xs:sequence> </xs:comlexType>
<xs:complexType> <xs:choice> <xs:element ref="somevalue"/> </xs:choice> </xs:comlexType>
<xs:complexType> <xs:all> <xs:element ref="somevalue"/> </xs:all> </xs:comlexType>
Apparently, the sequence
, choice
and all
are not necessary to for a single element, because they should by used to indicate the order of multiple elements. Is there a more concise way to declare a complexType
that has only one child element? (I.e. one that eliminates the use of sequence
, all
or choice
, somehow.)
An "elements-only" complex type contains an element that contains only other elements.
The complexType element defines a complex type. A complex type element is an XML element that contains other elements and/or attributes.
Define a Complex Type directly by naming. S.No. Complex Empty complex type element can only have attributes but no contents. Text-Only complex type element can only contain attribute and text. Mixed complex type element can contain element, attribute and text.
Just eliminating xs:sequence
, xs:choice
, or xs:all
, is not an option:
<xs:complexType name="cType">
<xs:element name="e"/>
</xs:complexType>
is not valid.
See XML Representation of Complex Type Definitions where complexType
's content model is defined as follows:
(annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
There is no provision for element
being a direct child of complexType
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With