Converting Complex-Type Elements from Local to Global - Exercise

Contact Us or call 1-877-932-8228
Converting Complex-Type Elements from Local to Global - Exercise

Converting Complex-Type Elements from Local to Global

Duration: 10 to 15 minutes.

In this exercise, you will convert the Artists element declaration in the song schema from local to global.

  1. Open ComplexTypes/Exercises/Song.xsd and save it as Song2.xsd in the same directory.
  2. Change the Artists element to be declared globally.
  3. Try to validate ComplexTypes/Exercises/TheGirlIsMine.xml against the schema you just created. If the XML document is invalid, fix your schema.

Solution:

ComplexTypes/Solutions/Song2.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
---- C O D E   O M I T T E D ----

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