Overview

Contact Us or call 1-877-932-8228
Overview

Overview

Complex-type elements have attributes, child elements, or some combination of the two. For example, the Name and HomePage elements below are both complex-type elements.

Code Sample:

ComplexTypes/Demos/ComplexType.xml
<?xml version="1.0"?>

<!--Person element is a complex-type--->
<Person>
	<Name>
		<!---FirstName and LastName elements have simple text--->
		<FirstName>Mark</FirstName>
		<LastName>Twain</LastName>
	</Name>
	<!---HomePage element is empty--->
	<HomePage URL="http://www.marktwain.com"/>
</Person>

As the diagram below shows, a complex-type element can be empty, contain simple content such as a string, or can contain complex content such as a sequence of elements.

Whereas it is not necessary to explicitly declare that a simple-type element is a simple type, it is necessary to specify that a complex-type element is a complex type. This is done with the xs:complexType element as shown below.

Syntax

<xs:element name="ElementName">
	<xs:complexType>
		<!--Content Model Goes Here-->
	</xs:complexType>
</xs:element>
Next