Elements and attributes: modeling relational data in XML, part 1

is parsed differently from this document:

This can make parsing difficult, depending on the parser library you use. You have to manually check all the child elements of the customer element to determine which one has the piece of information (the customer's name, for example) that is being searched for. Generating XML documents with this structure is also more difficult—the elements containing the data points must be serialized to the target document in exactly the right order, or the document does not validate against its DTD or schema.

On the other hand, attributes in an XML document are not order sensitive in much the same way that named columns are not order sensitive in a relational database table. Thus, the following two documents are parsed exactly the same way:


<customer>


       <address>123 Somewhere

    Street</address>


       <city>Randomtown</city>


       <state>WV</state>


       <zip>25423</zip>


       <name>Fred Q.

    Anybody</name>


    </customer>

and


    <customer


       name="Fred Q. Anybody"


       address="123 Somewhere Street"


       city="Randomtown"


       state="WV"


       zip="25423" />

Because these two documents parse the same way, they both validate against the same DTD or schema. Creating documents is easier as well, because you can add attributes to the XML document in any order convenient to you.

Differences in document size
Because of the way XML documents are serialized to text, attribute values use fewer characters than their equivalent element representations. For example, compare our two sample documents (assuming that all white space is removed to minimize document size):


    <customer


       name="Fred Q. Anybody"


       address="123 Somewhere Street"


       city="Randomtown"


       state="WV"


       zip="25423" />

Subscribers who liked this article also read:

<customer>


       <name>Fred Q.

    Anybody</name>


       <address>123 Somewhere

    Street</address>


       <city>Randomtown</city>


       <state>WV</state>


       <zip>25423</zip>


    </customer>
Advanced packages drive on-board programming innovations
by Peter T. Larsen. Intel Corp. Vendors such as Intel recognize t...

If you're interested in this topic, these articles may be helpful:

Custom ASP.NET DataGrid paging with Exact Count
by Dimitrios Markatos, independent .NET architect. Anybody in the D...
Semantic interoperability with universal data element framework
by Neelima Vobugari, XML certified independent software consultant. ...
Determine the correct XML parser type for a Java application
by Padma Apparao, senior performance architect, Software Solutions Gro...
Schema Plus Professional trial download
from SchemaPlus Schema Plus is an array of robust database management...
XMLSpy Home Edition 2005
from Altova Altova XMLSpy 2005 Home Edition is a free entry level X...

Related Jobs:

Engineering Manager / Chief Architect #0D2000E1CDEE90F2 - CA - West Hollywood - Ask Jeeves,Inc.
Title Engineering Manager / Chief Architect City West Hollywood St...
Data Migration Specialist #TEC00001143 - PA - Horsham - The Thomson Corporation
Data Migration Specialist TEC00001143 Job Description ...
Software Development Engineer - Web Applications #26ADD61C339077DF - CA - Oakland - Ask Jeeves,Inc.
Title Software Development Engineer - Web Applications City Oakland ...
Senior Web Applications Engineer #8476E6367126C442 - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...
Senior Web Applications Engineer #C8469CF29B4A750B - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...
Software Development Principal #002VF - TX - Dallas - Sabre Inc.
Software Development Principal 002VF Job Description ...
Web Facilitator #1544 - OH - Akron - RCG Information Technology
Description-Web Facilitator will assist with general website mainten...
Programmer - MI - Ann Arbor - MS&L Digital
Progressive digital office, located in the heart of modern downtown An...
.Net Developer #427842 - VA - Arlington - McDonald Bradley, Inc.
427842 - .Net Developer Jul 27, 2007 Arlington, Virginia Send ...
Microsoft Developer - Senior Consultant #1376 - MN - Richfield - Sogeti USA LLC
Microsoft Developer - Senior Consultant Req. ID: 1376 # Positions:...