Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 26th, 2006, 10:35 PM
res7cxbi@verizon.net
Guest
 
Posts: n/a
Default Store Data as an Attribute or a Node?

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?

  #2  
Old February 26th, 2006, 10:35 PM
res7cxbi@verizon.net
Guest
 
Posts: n/a
Default Re: Store Data as an Attribute or a Node?

sorry i meant "elements" not "nodes"

  #3  
Old February 26th, 2006, 10:45 PM
Joe Kesselman
Guest
 
Posts: n/a
Default Re: Store Data as an Attribute or a Node?

res7cxbi@verizon.net wrote:[color=blue]
> would one go with elements or attributes by the data involved or just
> sheer preference?[/color]

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
  #4  
Old February 26th, 2006, 10:45 PM
Crutcher Dunnavant
Guest
 
Posts: n/a
Default Re: Store Data as an Attribute or a Node?

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.

  #5  
Old February 26th, 2006, 10:55 PM
res7cxbi@verizon.net
Guest
 
Posts: n/a
Default Re: Store Data as an Attribute or a Node?

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

  #6  
Old February 27th, 2006, 10:05 PM
Peter Flynn
Guest
 
Posts: n/a
Default Re: Store Data as an Attribute or a Node?

res7cxbi@verizon.net wrote:[color=blue]
> 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?[/color]

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

///Peter
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles