473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Attributes vs. Values

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
Mar 1 '08 #1
1 2034
ja************@gmail.com 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
Mar 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Francis Avila | last post by:
A little annoyed one day that I couldn't use the statefulness of generators as "resumable functions", I came across Hettinger's PEP 288 (http://www.python.org/peps/pep-0288.html, still listed as...
7
by: Info 3000 | last post by:
Hello, I'm beginner in XML. I have just a little question : I understand that I can write : <Book> <Title> A nice day </Title> <Author> James Nicepen </Author> </Book>
6
by: Developer | last post by:
Hello, I'm experimenting with and XmlTextReader sample, and don't understand how the attributes are being processed. Here's the input: <xsd:element name="AA" type="BB"...
5
by: WindAndWaves | last post by:
Greetings once more, I was wondering if someone figured out the difference between attributes and properties. I noticed that things like fields have a number of properties, but also...
1
by: jaloplo | last post by:
Hi, I'm having a big problem cause I need to write attributes values without knowing the name of these attributes. For example, my xml file is like this: <element id="1" name="pepe"...
6
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def>...
23
by: Frank Millman | last post by:
Hi all I have a small problem. I have come up with a solution, but I don't know if it is a) safe, and b) optimal. I have a class with a number of attributes, but for various reasons I cannot...
0
by: jeoffh | last post by:
Background: I am trying to "merge" some attributes into an existing XML column in my MS SQL 2005 database. The general idea is that I have an XML column in a table and I would like to update/delete...
3
by: TechieGrl | last post by:
Hello. It's been awhile since I've been in the XML world, but before I go down a possibly unnecessary path, I wanted to ask about using CSS and XML files. Is it possible to style multiple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.