• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Attributes v's Elements

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the downside of using attributes over extra elements. Several books state that it is purely down to the designer's personal preference on using attributes or elements.

Personally I think that attributes are nicer as it doesn't bloat the xml.

Here are two examples with and without attributes. Which is best?

With Attributes
<RequestBatch ConsumerKey="..." Password="..." Language="..." DateTime="..." SerialID="...">
<Request RequestID="..." Company="..." SerialID="...">
...
</Request>
</RequestBatch>

Without Attributes
<RequestBatch>
<Authentication>
<ConsumerKey>...</ConsumerKey>
<Password>...</Password>
<Language>...</Language>
<DateTime>...</DateTime>
</Authentication>
<Request>
<RequestHeader>
<RequestID>...</RequestID>
<Company>...</Company>
<SerialID>...</SerialID>
</RequestHeader>
...
</Request>
</RequestBatch>
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guideline is if something feels like a "header" or like "meta-information", it goes into an attribute, if it feels like the actual information, it goes into an element. Totally subjective, obviously, and a very flexible rule

There are technical considerations as well, of course - some of the things that can go into a CDATA section can't be put into an attribute. And elements have an ordering, while attributes don't.

Since you're asking in the WS forum, this thread might be of interest to you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic