Using Elements to Define Hierarchy




Download 2,96 Mb.
Pdf ko'rish
bet62/131
Sana14.05.2024
Hajmi2,96 Mb.
#232039
1   ...   58   59   60   61   62   63   64   65   ...   131
Bog'liq
Ceponkus, Hoodbhoy - Applied XML - Toolkit for Programmers

Using Elements to Define Hierarchy
The hierarchy of information is encoded by the nesting of tags. Tags can be nested to an 
arbitrary length in XML documents. By using nested elements, you automatically 
introduce a hierarchical (and rich) description of your information.
If that sounds too abstract, allow us to solidify the concept with an example. Let’s use the 
example of an address book. An address from this book consists of people, individually 
referred to as 
contacts
. Each contact consists of a name, a telephone number, and an 
address. Each telephone number consists of an area code and a phone number. Each 
address consists of a street name, a city, a state, and a ZIP code. Figure 3.3 shows what 
the structure of our address book looks like conceptually.
Figure 3.3:
Conceptual structure of address book.
XML can be represented in many ways, but since we are trying to illustrate how to use 
elements, we are going to limit ourselves to using only elements.


Alley Gator
515
5551235



- 57 -
112, Main Street
Mudy Waters
FL
55544



As you can see, some elements (ADDRESS_BOOK, CONTACT, PHONE, ADDRESS) 
are used only to provide structure while other elements (NAME, AREA_CODE, 
PHONE_NUMBER, STREET_ADDRESS, CITY, STATE, ZIP) actually contain 
information. Intuitively, you can see that because the data is so richly structured, given a 
complete database of contacts, you could perform searches or sorting based on city 
information, area code, or name. Intuitively, you can also see that because the NAME 
element is not broken up into a FIRST_NAME and LAST_NAME, simple sorting involving 
the content of the NAME element would be done on the basis of the contact’s first name.
Figure 3.4 shows how Internet Explorer displays the above raw XML file. Internet 
Explorer 5.0 has a built-in MIME Type viewer that allows you to dynamically view the 
contents and structure of raw XML files. 

Download 2,96 Mb.
1   ...   58   59   60   61   62   63   64   65   ...   131




Download 2,96 Mb.
Pdf ko'rish