Adding ComplexType Elements - Exercise

Welcome to our free XML Schema tutorial. This tutorial is based on Webucator's Introduction to XML Schema course.

Contact Us or call 1-877-932-8228
Adding ComplexType Elements - Exercise

Adding ComplexType Elements

Duration: 15 to 25 minutes.

In this exercise, you will modify the song schema, adding model groups and occurrence constraints.

  1. Open ComplexTypes/Exercises/Song.xsd for editing.
  2. Modify the schema so that the Song element's children can appear in any order.
  3. Change the content model of the Song element so that it contains an Artists element in place of the Artist element.
  4. Make the Artists element allow for one or more child Artist elements. Note that the Artist element is already declared globally.
  5. Make the Length element optional.
  6. Try to validate ComplexTypes/Exercises/WeAreTheWorld.xml against the schema you just created. If the XML document is invalid, fix your schema.


<?xml version="1.0"?>
<xs:schema xmlns:xs="">
---- C O D E   O M I T T E D ----

	<xs:element name="Song">
				<xs:element ref="Title"/>
				<xs:element ref="Year"/>
				<xs:element name="Artists">
							<xs:element ref="Artist" maxOccurs="unbounded"/>
				<xs:element ref="Length" minOccurs="0"/>

This tutorial is based on Webucator's Introduction to XML Schema Course. We also offer many other XML Training courses. Sign up today to get help from a live instructor.