Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Attributes vs. Values

Reply
Thread Tools

Attributes vs. Values

 
 
jason.cipriani@gmail.com
Guest
Posts: n/a
 
      03-01-2008
I'm just recently starting to use XML for storing data, and I am
wondering when it is more appropriate to use child node values instead
of node attributes -- and in general, what are good ways to structure
the XML. For example, let's say I want to store information about the
furniture in a room. This room has a red, wooden chair. It has a
green ceramic lamp. It also has a white end table made of, I don't
know, let's say human bone (scary!). So one way I could say this in
XML is:

<furniture>
<chair>
<color>red</color>
<material>wood</material>
</chair>
<lamp>
<color>green</color>
<material>ceramic</color>
</lamp>
<table>
<type>endtable</type>
<color>white</color>
<material>bone</material>
</table>
</furniture>

Ok... but I could also do, say:

<item what="chair">
...
</item>
<item what="lamp">
...
</item>
<item what="table">
...
</item>

Or for that table, I can remove "type" child node and make that an
attribute, maybe that is more appropriate:

<item what="table" subtype="endtable">...</item>

Or I could just use attributes for everything (this one seems to be
the most natural to me...):

<furniture>
<chair color="red" material="wood"/>
<lamp color="green" material="ceramic"/>
<table color="white" material="bone" type="end"/>
</furniture>

Or I could combine the above two:

<furniture>
<item what="chair" color="red" material="wood"/>
<item what="lamp" color="green" material="ceramic"/>
<item what="table" color="white" material="bone" type="end"/>
</furniture>

I could even do this:

<item what="chair">
<color value="red"/>
<material value="ceramic"/>
</item>

Or this:

<item>
<property name="what" value="chair"/>
<property name="color" value="red"/>
<property name="material" value="ceramic"/>
</item>

Or this:

<item>
<property name="what">chair</property>
<property name="color">red</property>
<property name="material">ceramic</property>
</item>

Or any number of the infinite other possibilities I can think of...

When does it make sense to use values vs. attributes? When does it
make sense to have different child node types (like "chair", "lamp",
"table") rather than the same child node types but different
attributes (all child nodes are "item" but they have a "what"
attribute)?

It's really confusing because I have so many options.

Thanks,
Jason
 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      03-01-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I'm just recently starting to use XML for storing data, and I am
> wondering when it is more appropriate to use child node values instead
> of node attributes


There is an article on this in the XML FAQ:
http://xml.silmaril.ie/developers/attributes/

///Peter
 
Reply With Quote
 
 
 
 
jason.cipriani@gmail.com
Guest
Posts: n/a
 
      03-01-2008
On Mar 1, 4:56 pm, Peter Flynn <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > I'm just recently starting to use XML for storing data, and I am
> > wondering when it is more appropriate to use child node values instead
> > of node attributes

>
> There is an article on this in the XML FAQ:http://xml.silmaril.ie/developers/attributes/


Thanks for that! That's exactly the kind of info I was looking for.

"Beginners always ask this question. Those with a little experience
express their opinions passionately. Experts tell you there is no
right answer."

Makes me feel a little more secure about asking this question; and
reading through everything else makes me feel a lot better about just
picking whatever is easier in the situation.

Jason
 
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
data attributes override method attributes? Jayden Python 16 09-29-2012 03:20 AM
attributes ala java annotations or .Net attributes? Kyle Schmitt Ruby 3 07-24-2007 07:48 PM
class attributes & data attributes james_027 Python 2 06-20-2007 03:12 PM
WebControl.Attributes.Add and custom attributes P4trykx ASP .Net 2 01-31-2007 04:33 PM
Parse reserved attributes as normal attributes Max XML 1 09-22-2006 12:04 PM



Advertisments