xml programming
rss xml feed
xml code
xml tutorial
xml editor
xml format
xml web services
xml reader
xml validator
xml language
java script xml
xml databases
xml network india
xml rules
xml file
xml software
professional xml
xml schema validation
xml visual studio
xml parsers
xml consultants india
xml document
Principles of XML design: when to use elements versus attributes

The oldest question asked by adopters of XML is when to use elements and when to use attributes in XML design. As with most design issues, this question rarely has absolute answers, but developers have also experienced a lack of very clear guidelines to help them make this decision.

by Uche Ogbuji, principal consultant, Fourthought, Inc. First published by IBM at IBM developerWorks XML (www.ibm.com/developerworks/xml). All rights retained by IBM and the author.


The oldest question asked by adopters of XML is when to use elements and when to use attributes in XML design. As with most design issues, this question rarely has absolute answers, but developers have also experienced a lack of very clear guidelines to help them make this decision. In this article, Uche Ogbuji offers a set of guiding principles for what to put in elements and what to put in attributes.


Several frequently pondered questions of DTD design in SGML have followed the legacy to its offshoot, XML. Regardless of what XML schema language you use, you might find yourself asking:
* When do I use elements and when do I use attributes for presenting bits of information?
* When do I require an order for elements, and when do I just allow arbitrary order?
* When do I use wrapper elements around sequences of similar elements?

In my experience working with users of XML, the first question is by far the most common. In some cases the answer is pretty unambiguous:
* If the information in question could be itself marked up with elements, put it in an element.
* If the information is suitable for attribute form, but could end up as multiple attributes of the same name on the same element, use child elements instead.
* If the information is required to be in a standard DTD-like attribute type such as ID, IDREF, or ENTITY, use an attribute.
* If the information should not be normalized for white space, use elements. (XML processors normalize attributes in ways that can change the raw text of the attribute value.)


Unfortunately, design decisions don't often fall into such neat categories. The question remains how to make the right choice in the gray areas. The usual answer is No single answer is right, use your best judgment. But this is not very helpful for those trying to find their feet with XML. True, even experts do not always agree on what to do in certain situations, but this is no reason not to offer basic guidelines for choosing between XML and attributes.
First I want to comment on two guidelines that I have heard and do not recommend. I have heard Just make everything an element.

The reasons given range from Attributes just complicate things to Attributes can stunt extensibility. But if you do not use attributes, you are leaving out a very important aspect of XML's power, and you're probably better off using some delimited text format.


I have also heard If it is the sort of material you would expect to display in a browser, use element content. The problem with this guideline is that it encourages people to think of XML content design in terms of presentation, two considerations that should not be mixed. I present a very similar guideline in this article, but I express it in terms of the intent of the content, rather than in terms of presentation.


In the rest of this article, I present a set of guidelines that I do recommend when choosing between elements and attributes.
Recommended guidelines


I have divided these guidelines into a set of principles that I think frame the choice between elements and attributes overall. None of the guidelines are meant to be absolute; use them as rules of thumb and feel free to break the rules whenever your particular needs require it. Principle of core content:


If you consider the information in question to be part of the essential material that is being expressed or communicated in the XML, put it in an element. For human-readable documents this generally means the core content that is being communicated to the reader.

For machine-oriented records formats this generally means the data that comes directly from the problem domain. If you consider the information to be peripheral or incidental to the main communication, or purely intended to help applications process the main communication, use attributes. This avoids cluttering up the core content with auxiliary material. For machine-oriented records formats, this generally means application-specific notations on the main data from the problem-domain.

As an example, I have seen many XML formats, usually home-grown in businesses, where document titles were placed in an attribute. I think a title is such a fundamental part of the communication of a document that it should always be in element content. On the other hand, I have often seen cases where internal product identifiers were thrown as elements into descriptive records of the product. In some of these cases, attributes were more appropriate because the specific internal product code would not be of primary interest to most readers or processors of the document, especially when the ID was of a very long or inscrutable format.

Grab this Limited time OFFER. List your website here FREE !
 
xml-dev - RE: [xml-dev] XML-aware programming language?
Lists Home | Date Index | Thread Index] To: "Jonathan Robie" < jonathan.robie@datadirect.com >,"Daniela Florescu" < dflorescu@mac.com > Subject: RE: [xml-dev] XML-aware programming ...
http://lists.xml.org/archives/xml-dev/200412/msg00122.html
 
XML Programming, XML Help, XML Tips, XML Methods, XML Tricks
XML Programming, XML Help, XML Tips, XML Methods, XML Tricks ... XML PROGRAMMING, XML HELP, XML TIPS, XML METHODS, XML TRICKS
http://www.devshed.com/c/b/XML/
 
XML Development:
This forum is for discussing XML, including XUL and XSL.. Browser Side World XML Development ... XML Development: Forum Charter, Library, Moderated by: httpwebwitch: Forum Options ...
http://www.webmasterworld.com/forum26/
 
XML Programming Core Reference Comments and Corrections
This article contains comments, corrections, and information about known errors relating to the Microsoft Press book XML Programming Core Reference, ISBN 0-7356-1185-8. The ...
http://support.microsoft.com/kb/318910
 
XML Programming Forums
XML Programming, XML Programming forum discussing XML and related technologies, including XUL and XSL. XML is a self-describing file format, designed for maximum compatibility ...
http://forums.devshed.com/xml-programming-19/
 
xml programming news
EZConnect EDI-XML Implementation Toolkit Enables SAP Shops To Bypass iDocs, Set Up XML Trading Partner Documents Fast (EnterpriseContentManagementConnection-ECM)
ACOM Solutions, Inc. has introduced a SAP-specific implementation toolkit for its NET-compliant EZConnect EDI and XML data translation and trading partner management solution that speeds and simplifies mapping of electronic trading partner documents for exchange between the SAP software environment and software systems used by customers or vendors, it was announced recently by Mark Firmin, vice ...
 
Iraq, Saudis reach anti-terror agreement (Moldova.org)
Iraqi officials say they and Saudi Arabia officials have agreed to a continuation of their joint effort to fight terrorism.Financial transactions between the two countries will be a special focus under an agreement reached during a recent visit to Saudi Arabia by Iraqi Security Adviser Dr. Muwafaq Al-Rubaie, the Kuwait News Agency, KUNA, reported Sunday.A statement issued by the Iraqi government ...
 
Rice to talk anti-terror in Morocco (Moldova.org)
U.S. Secretary of State Condoleezza Rice will focus on anti-terrorism efforts during her Sunday visit to Morocco, sources say. On the final leg of her North African tour, unnamed sources told the BBC that Rice is likely to focus on Morocco's efforts to fight al-Qaida terrorist cells in the Western Sahara region when she meets with the nation's leaders.Morocco claims to have broken up more than ...
 
Powerful Hurricane Ike approaches Cuba (Moldova.org)
Hurricane Ike, a powerful and dangerous Category 4 storm, bore down on Cuba Sunday with sustained winds of near 135 mph, meteorologists said. As of 5 a.m. Sunday, Ike was located 65 miles east of the Bahamas' Great Inagua Island, moving nearly due west at 15 mph. Forecasters from the U.S. National Weather Service's National Hurricane Center in Miami predicted Ike would traverse Cuba lengthwise ...
 
St. Paul mayor hits hole in one (Moldova.org)
It was a big week for St. Paul, Minn., Mayor Chris Coleman: his town played host to a national political convention and he hit a hole in one.No sooner had Republicans left town after nominating John McCain as their presidential candidate, than Coleman found himself out on a golf course for a Cystic Fibrosis Foundation charity event Friday. On the par 3 No. 8 at Highland National Golf Course, he ...
 
Tropical Storm Josephine dissipating (Moldova.org)
Tropical Storm Josephine was downgraded to a tropical depression as its strength dissipated as it approached the Cape Verde Islands, weather officials say.A National Hurricane Center Bulletin Saturday said the former tropical storm is expected to dissipate even further as it travels the nearly 855 remaining miles to the Atlantic Ocean islands.Hurricane Center forecasters said the depression ...
 
Jesse Jackson Sr. released from hospital (Moldova.org)
The Rev. Jesse Jackson Sr. was out of a Chicago hospital after suffering stomach pains, hospital officials say.Officials of Northwestern Memorial Hospital said the civil rights leader and one-time Democratic U.S. presidential candidate was much improved and was released Friday, the Chicago Sun-Times reported. A spokeswoman for Jackson's Rainbow/PUSH organization said the 66-year-old was planning ...
 
Newspaper's 'Obama Clock' set to 11:48 (Moldova.org)
A Chicago newspaper says it wants its readers to tell it where the hands should be on its Obama Clock.The feature in the Chicago Sun-Times shows the face of the Democratic U.S. presidential nominee superimposed on a clock. The newspaper says that when the hands reach midnight, it signals Obama has been elected president, but if they're moved to 11:30, it means he's lost. With fewer than 60 days ...
 
U.S. missile strike targets Afghan border (Moldova.org)
A U.S. missile strike killed several people in Afghanistan very close to its border with Pakistan, local residents say. Quoting a journalist based in the Pakistani tribal region of North Waziristan, The New York Times reported Saturday that residents of Al Must, Afghanistan, say missiles fired Friday from a drone aircraft killed six to 12 men of Arab descent. The missile attack came just days ...
 
Man doesn't deliver on Make-a-Wish pledge (Moldova.org)
An Illinois boy with a kidney disease is still waiting for a custom go-kart promised by an Arizona man through the Make-a-Wish Foundation, officials say. Brent Goodrich, a spokesman for Make-a-Wish, says Douglas Riesberg of Yuvapai County, Ariz., defrauded the charity of $11,000, which he allegedly took to build the go-kart for the unnamed 16-year-old boy from Peoria, Ill., WBBM-AM, Chicago, ...