I'm having some confusion on the type simpletype
, simplecontent
, complextype
and complexcontent
.
I'm almost new to xsd. Can someone help to clear the confusion that giving concrete examples.
I know it's a bit late but I hope this article helps someone.
In short:
<complexType>
and <simpleType>
both define types. Complex types can have element descendants and attributes while simple types can't.
Complex types can have simple or complex content. Types with <complexContent>
can contain child elements while those with <simpleContent>
can only contain characters.
What is a Complex Element?
A complex element is an XML element that contains other elements and/or attributes. There are four kinds of complex elements:
Note: Each of these elements may contain attributes as well!
Examples of Complex Elements
<product pid="1345"/>
<employee>
<firstname>Deepam</firstname>
<lastname>Gupta</lastname>
</employee>
<food type="dessert">Chapati</food>
<description>
It happened on <date lang="hindi">18.03.99</date> ....
</description>
Another good XSD tutorial here.
Basically
xs:simpleType define a value type, this value can then be used within an element or attribute (so you could define an double with 2 decimal places or a string in the format of an IP address).
xs:complexTypes describe the structure of an element. It can define its textual value, its attributes and its child elements. The textual value and attribute values are described by xs:simpleType's.
SimpleType can only have value within the closing tag as follows:
<SimpleType>Antony</SimpleType>
Whereas
ComplexType can have children with attributes as follows:
<complexType name="xx">
<complexContent>
<extension base="xx">
<sequence>
<element name="xx" type="xx" minOccurs="1" maxOccurs="1" />
</sequence>
</extension>
</complexContent>
</complexType>