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 tha...

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...
XMLSpy Home Edition 2005
from Altova Altova XMLSpy 2005 Home Edition is a free entry level X...
Semantic interoperability with universal data element framework
by Neelima Vobugari, XML certified independent software consultant. ...
Schema Plus Professional trial download
from SchemaPlus Schema Plus is an array of robust database management...
Determine the correct XML parser type for a Java application
by Padma Apparao, senior performance architect, Software Solutions Gro...

Related Jobs:

Senior Web Applications Engineer #8476E6367126C442 - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...
Web Facilitator #1544 - OH - Akron - RCG Information Technology
Description-Web Facilitator will assist with general website mainten...
Database & Java Developer #61559 - NY - Depew - HSBC Bank Usa
Database & Java Developer Here are all the details for this position....
Senior Web Applications Engineer #C8469CF29B4A750B - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...
Senior Research Engineer #F2FDC48FE3C2DAE3 - CA - Oakland - Ask Jeeves,Inc.
Title Senior Research Engineer City Oakland State CA Zip Code 94...
Technical Yahoo #RX1000023474 - CA - Sunnyvale - Yahoo! Inc.
Technical Yahoo Job No. RX1000023474 Location US - Sunnyvale ...
Web Developer/Front End #RX1000022062 - CA - Sunnyvale - Yahoo! Inc.
Web Developer/Front End, Structured Web Search Job No. RX10000...
Software Development Principal #002VF - TX - Dallas - Sabre Inc.
Software Development Principal 002VF Job Description ...
Web Developer/Front End #RX1000020442 - CA - Sunnyvale - Yahoo! Inc.
Web Developer/Front End - Structured Web Search Job No. RX1000020...
Sr. C# .Net OO Developer #3741826 - TX - Houstan - Ajilon
Description : If you're a professional looking for exciting, new oppo...