Store Data as an Attribute or a Node?

Discussion in 'XML' started by res7cxbi@verizon.net, Feb 26, 2006.

  1. Guest

    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?
     
    , Feb 26, 2006
    #1
    1. Advertising

  2. Guest

    sorry i meant "elements" not "nodes"
     
    , Feb 26, 2006
    #2
    1. Advertising

  3. 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
     
    Joe Kesselman, Feb 26, 2006
    #3
  4. 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.
     
    Crutcher Dunnavant, Feb 26, 2006
    #4
  5. Guest

    I'll probably go with elements because im more familiar with those.
    Thanks for such a quick reply.
     
    , Feb 26, 2006
    #5
  6. Peter Flynn Guest

    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
     
    Peter Flynn, Feb 27, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,620
  2. CB
    Replies:
    1
    Views:
    605
    Johannes Koch
    Oct 2, 2003
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,484
    Dimitre Novatchev
    Aug 24, 2006
  4. Replies:
    1
    Views:
    585
    Martin Honnen
    May 8, 2007
  5. Stefan_W
    Replies:
    1
    Views:
    8,342
    Stefan_W
    Nov 5, 2008
Loading...

Share This Page