• Post Reply Bookmark Topic Watch Topic
  • New Topic

Attributes v's Elements  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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: 42975
76
  • Mark post as helpful
  • send pies
  • 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.
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!