J
jason.cipriani
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
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