[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
XSD Complex Types describe element content if this content is using attributes and/or element content other than only character data. Thus, complex types are used to define the allowed markup structures for a class of documents. Using XSD's type concepts, it is easier to represent model-level information in a schema, because type hierarchies can represent model-level specializations.
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="billingAddress" type="addressType"/> <xs:element name="shippingAddress" type="addressType"/> <xs:complexType name="addressType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string" minOccurs="0"/> <xs:element name="zip" type="xs:decimal"/> </xs:sequence> <xs:attribute name="country" type="xs:NMTOKEN"/> </xs:complexType> </xs:schema>
Simple Types | Complex Types | |||
---|---|---|---|---|
Simple Content | Complex Content | |||
Element Only | Mixed | Empty |
,
) and alternatives (|
)#PCDATA
into the content model( #PCDATA | a | b )*
mixed
attribute on the type marks the type as being mixed<xs:element name="p" type="mixedType"/> <xs:complexType name="mixedType" mixed="true"> <xs:choice maxOccurs="unbounded" minOccurs="0"> <xs:element ref="b"/> <xs:element name="i" type="xs:string"/> <xs:element name="u" type="xs:string"/> </xs:choice> <xs:attribute ref="class"/> </xs:complexType>
EMPTY
is used<?xml version="1.0" encoding="UTF-8"?> <person> <name> <givenname>Erik</givenname> <givenname>Thomas</givenname> <surname>Wilde</surname> </name> <address> <company>ETH Zürich</company> <email>net.dret@dret.net</email> </address> </person>
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="name"> <xs:complexType> <xs:sequence> <xs:element name="givenname" type="xs:token" maxOccurs="unbounded"/> <xs:element name="surname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="address"> <xs:complexType> <xs:sequence> <xs:element name="company" type="xs:string"/> <xs:element name="email" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value=".*@.*\..*"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="person" type="personType"/> <xs:complexType name="personType"> <xs:sequence> <xs:element name="name" type="nameType"/> <xs:element name="address" type="addressType"/> </xs:sequence> </xs:complexType> <xs:complexType name="nameType"> <xs:sequence> <xs:element name="givenname" type="givennameType" maxOccurs="unbounded"/> <xs:element name="surname" type="surnameType"/> </xs:sequence> </xs:complexType> <xs:simpleType name="givennameType"> <xs:restriction base="xs:token"/> </xs:simpleType> <xs:simpleType name="surnameType"> <xs:restriction base="xs:string"/> </xs:simpleType> <xs:complexType name="addressType"> <xs:sequence> <xs:element name="company" type="companyType"/> <xs:element name="email" type="emailType" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:simpleType name="companyType"> <xs:restriction base="xs:string"/> </xs:simpleType> <xs:simpleType name="emailType"> <xs:restriction base="xs:string"> <xs:pattern value=".*@.*\..*"/> </xs:restriction> </xs:simpleType> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element ref="name"/> <xs:element ref="address"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="name"> <xs:complexType> <xs:sequence> <xs:element ref="givenname" maxOccurs="unbounded"/> <xs:element ref="surname"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="givenname" type="xs:token"/> <xs:element name="surname" type="xs:string"/> <xs:element name="address"> <xs:complexType> <xs:sequence> <xs:element ref="company"/> <xs:element ref="email" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="company" type="xs:string"/> <xs:element name="email"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value=".*@.*\..*"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="person" type="personType"/> <xs:element name="name" type="nameType"/> <xs:element name="givenname" type="givennameType"/> <xs:element name="surname" type="surnameType"/> <xs:element name="address" type="addressType"/> <xs:element name="company" type="companyType"/> <xs:element name="email" type="emailType"/> <xs:complexType name="personType"> <xs:sequence> <xs:element ref="name"/> <xs:element ref="address"/> </xs:sequence> </xs:complexType> <xs:complexType name="nameType"> <xs:sequence> <xs:element ref="givenname" maxOccurs="unbounded"/> <xs:element ref="surname"/> </xs:sequence> </xs:complexType> <xs:simpleType name="givennameType"> <xs:restriction base="xs:token"/> </xs:simpleType> <xs:simpleType name="surnameType"> <xs:restriction base="xs:string"/> </xs:simpleType> <xs:complexType name="addressType"> <xs:sequence> <xs:element ref="company"/> <xs:element ref="email" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:simpleType name="companyType"> <xs:restriction base="xs:string"/> </xs:simpleType> <xs:simpleType name="emailType"> <xs:restriction base="xs:string"> <xs:pattern value=".*@.*\..*"/> </xs:restriction> </xs:simpleType> </xs:schema>
type layerto schema languages