XML Schema Definition Part 4


XML with Multiple Records

In this post we look at building our XSD to allow for multiple records/rows of data. We are building our knowledge of writing XSD files from scratch, slowly. Here we have a list of people where each person has a first name and a last name. We can have as many people in the list as we want. Our root element is People. Within that we have several People. Within People we have FirstName and LastName. Below is a diagram of our project provided by the Eclipse IDE.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://porterwebsites.com/People"
	xmlns:peo="http://porterwebsites.com/People" elementFormDefault="qualified">

	<element name="People" type="peo:People" />
	<complexType name="People">
		<sequence>
			<element name="Person" type="peo:Person" maxOccurs="unbounded" />
		</sequence>
	</complexType>
	<complexType name="Person">
		<sequence>
			<element name="FirstName" type="string" />
			<element name="LastName" type="string" />
		</sequence>
	</complexType>
</schema>

Below is an example XML document that is well-formed and validates against the above schema definition.

<?xml version="1.0" encoding="UTF-8"?>
<peo:People xmlns:peo="http://porterwebsites.com/People"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://porterwebsites.com/People People.xsd ">
	<peo:Person>
		<peo:FirstName>John</peo:FirstName>
		<peo:LastName>Johnson</peo:LastName>
	</peo:Person>
	<peo:Person>
		<peo:FirstName>Jack</peo:FirstName>
		<peo:LastName>Jackson</peo:LastName>
	</peo:Person>
		<peo:Person>
		<peo:FirstName>Don</peo:FirstName>
		<peo:LastName>Donaldson</peo:LastName>
	</peo:Person>
</peo:People>
Series Navigation<< XML Schema Definition Part 3XML Schema Definition Part 5 >>

Leave a comment

Your email address will not be published. Required fields are marked *