Adding Nonatomic Types - Exercise

Contact Us or call 1-877-932-8228
Adding Nonatomic Types - Exercise

Adding Nonatomic Types

Duration: 10 to 15 minutes.

In this exercise, you will add a nonatomic type to the song schema.

  1. Open SimpleTypes/Exercises/Song2.xsd and save it as Song3.xsd in the same directory.
  2. Define a new simple type called SongLength, which is an enumeration of three values: "Short", "Medium', and "Long".
  3. Define another new simple type called SongTime, which is a union of xs:duration and SongLength.
  4. At the end of the sequence of elements within the Song element, insert an additional element, Length, which is of the SongTime datatype.
  5. Try to validate SimpleTypes/Exercises/TicketToRide.xml and SimpleTypes/Exercises/EleanorRigby.xml against the schema you just created. If either XML document is invalid, fix your schema.


<?xml version="1.0"?>
<xs:schema xmlns:xs="">
	<xs:simpleType name="ProperName">
		<xs:restriction base="xs:string">
			<xs:whiteSpace value="collapse"/>
			<xs:pattern value="([A-Z0-9][A-Za-z0-9\-']* ?)+"/>
	<xs:simpleType name="Year">
		<xs:restriction base="xs:gYear">
			<xs:minInclusive value="1950"/>
			<xs:maxInclusive value="1970"/>
	<xs:simpleType name="SongLength">
		<xs:restriction base="xs:string">
			<xs:enumeration value="Short"/>
			<xs:enumeration value="Medium"/>
			<xs:enumeration value="Long"/>
	<xs:simpleType name="SongTime">
		<xs:union memberTypes="xs:duration SongLength"/>
	<xs:element name="Song">
				<xs:element name="Title" type="ProperName"/>
				<xs:element name="Year" type="Year"/>
				<xs:element name="Artist" type="ProperName"/>
				<xs:element name="Length" type="SongTime"/>