Store Data as an Attribute or a Node?

R

res7cxbi

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?
 
J

Joe Kesselman

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

Crutcher Dunnavant

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

res7cxbi

I'll probably go with elements because im more familiar with those.
Thanks for such a quick reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top