Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Store Data as an Attribute or a Node?

Reply
Thread Tools

Store Data as an Attribute or a Node?

 
 
res7cxbi@verizon.net
Guest
Posts: n/a
 
      02-26-2006
hi,

im familiar with xml but wondering if it would be better to store data
within attributes:

<root>
<data value="someData"/>
</root>

or within nodes:

<root>
<data>someData</data>
</root>

would one go with nodes or attributes by the data involved or just
sheer preference?

 
Reply With Quote
 
 
 
 
res7cxbi@verizon.net
Guest
Posts: n/a
 
      02-26-2006
sorry i meant "elements" not "nodes"

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      02-26-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> would one go with elements or attributes by the data involved or just
> sheer preference?


Mostly preference and sense of style.

Generally, elements and their content are used to convey
structural/essential information and attibutes are used to convey
annotations about how that information should be interpreted... but
that's a matter of usage convention; it isn't enforced.

Attributes can *not* have substructure, so some things that you might
prefer to consider attributes will wind up needing to be elements. The
order of attributes within a single start-element tag is officially Not
Meaningful, which also may or may not affect what you want to use them
for; they only permit a single value per name, which again constrains them.

There isn't a single perfect answer, in most cases. I would suggest you
look at the XML-based languages written by the W3C itself and model your
markup on those. That may not yield the perfect answer, but at least it
will follow people's expectations.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Crutcher Dunnavant
Guest
Posts: n/a
 
      02-26-2006
In all seriousness, It depends.

Generally, putting your data in text nodes:
<data>someData</data>

Is frequently easier to work with, especially if you might change your
mind, and add xml later.

However, if the data is small, and will _never_ contain xml nodes, you
can safely put it in attributes, which sometimes looks better, and may
be easier to work with in XSLT.

 
Reply With Quote
 
res7cxbi@verizon.net
Guest
Posts: n/a
 
      02-26-2006
I'll probably go with elements because im more familiar with those.
Thanks for such a quick reply.

 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      02-27-2006
(E-Mail Removed) wrote:
> hi,
>
> im familiar with xml but wondering if it would be better to store data
> within attributes:
>
> <root>
> <data value="someData"/>
> </root>
>
> or within nodes:
>
> <root>
> <data>someData</data>
> </root>
>
> would one go with nodes or attributes by the data involved or just
> sheer preference?


This is a FAQ, see http://xml.silmaril.ie/developers/attributes/

///Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to find a elements Xpath and store it as a attribute provowallis Python 1 10-06-2006 06:38 PM
XSLT: Making attribute to parent attribute Bostonasian XML 1 09-18-2005 07:30 AM
Re: How to store "3D" data? (data structure question) Sebastian Bassi Python 0 07-20-2005 07:54 PM
How to store "3D" data? (data structure question) Sebastian Bassi Python 5 07-20-2005 07:30 PM
to store or not to store an image =?Utf-8?B?UnVkeQ==?= ASP .Net 6 03-30-2005 05:51 AM



Advertisments