XML Examples -- How XML Works

Here are some XML samples which illustrate its simplicity and flexibility, followed by a brief description of how XML works.

Here's a sample describing two people, with their first and last names:

<person>
	<firstName>Jane</firstName>
	<lastName>Smith</lastName>
</person>
<person>
	<firstName>Evelyn</firstName>
	<lastName>Doe</lastName>
</person>

Now let's add their eye colors and their height in meters:

<person>
	<firstName>Jane</firstName>
	<lastName>Smith</lastName>
	<eyes>brown</eyes>
	<ht>1.5</ht>
</person>
<person>
	<firstName>Evelyn</firstName>
	<lastName>Doe</lastName>
	<eyes>blue</eyes>
	<ht>1.5234782</ht>
</person>

Now suppose Jane Smith has two pet dogs:

<person>
	<firstName>Jane</firstName>
	<lastName>Smith</lastName>
	<eyes>brown</eyes>
	<ht>1.5</ht>

	<pet>
		<petType>dog</petType>
		<petName>Snoopy</petName>
		<petBreed>Golden Retriever</petBreed>
	</pet>

	<pet>
		<petType>dog</petType>
		<petName>Fido</petName>
		<petBreed>German Shepherd</petBreed>
	</pet>

</person>
<person>
	<firstName>Evelyn</firstName>
	<lastName>Doe</lastName>
	<eyes>blue</eyes>
	<ht>1.5234782</ht>
</person>

How XML works:

	<!ELEMENT person (
		firstName,
		lastName,
		eyes?,
		ht?,
		pet*
		)>

	<!ELEMENT firstName (#PCDATA)>
	<!ELEMENT lastName (#PCDATA)>
	<!ELEMENT eyes (#PCDATA)>
	<!ELEMENT ht (#PCDATA)>

	<!ELEMENT pet (
		petType,
		petName,
		petBreed?,
		)>

	<!ELEMENT petType (#PCDATA)>
	<!ELEMENT petName (#PCDATA)>
	<!ELEMENT petBreed (#PCDATA)>
        

This tells you that:

For more information, see the section on XML Documentation.