Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a complexType has only one child element?

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.)

like image 483
MengT Avatar asked Oct 07 '13 11:10

MengT


People also ask

Which complex type signifies that only one of the child elements can appear?

An "elements-only" complex type contains an element that contains only other elements.

What does complexType mean in XSD?

The complexType element defines a complex type. A complex type element is an XML element that contains other elements and/or attributes.

How do you refer to complex type in XSD?

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.


1 Answers

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.

like image 105
kjhughes Avatar answered Oct 20 '22 11:10

kjhughes