Datasheet
Try It Out Creating a Simple XML Document
The data shown below represents three regions containing six countries:
Africa Zambia
Africa Zimbabwe
Asia Burma
Australasia Australia
Caribbean Bahamas
Caribbean Barbados
Here, you are going to create a single hierarchy XML document. The example shown in Figure 1-3, and
its preceding matching XML data, gives you an example to base this task on.
Create the XML document as follows:
1. Use an appropriate editor to create the XML document text file (Notepad in Windows).
2. Create the XML tag:
<?xml version=”1.0”?>
3. Create the root tag first. The data is divided up as countries listed within continents (regions).
Countries are contained within regions. There are multiple regions so there has to be a tag,
which is a parent tag of the multiple regions. If there was a single region there could be a single
<region> tag as the root node. So create a root node such as <regions>, indicating multiple
regions. The XML document now looks something like this:
<?xml version=”1.0”?>
<regions>
</regions>
4. Now add each region in as a child of the <regions> tag. It should look something like this:
<?xml version=”1.0”?>
<regions>
<region>Africa</region>
<region>Asia</region>
<region>Australasia</region>
<region>Caribbean</region>
</regions>
5. Next you can add the individual countries into their respective regions by creating individual
<country> tags:
<?xml version=”1.0”?>
<regions>
<region>Africa</region>
<country>Zambia</country>
<country>Zimbabwe</country>
6
Chapter 1
04_791202 ch01.qxp 10/6/06 10:59 AM Page 6