XML attributes or node ?

R

R.A.F.

Hi,

When i see a XML file i'm still wondering what are the differences
between writing node data as node attributes or as children nodes.

for example, what are the advantage to write such thing :
<setting>
<client>
<name>Vaporex</name>
<address>Saint Hope st.</address>
</client>
</setting>

instead of :
<setting>
<client name="Vaporex" address="Saint Hope st."></client>
</setting>

my question is the following one :
- which XML structure make a node or attribute research faster ?


Moreover, what should be written as attribute and what should be written
as children node ?

thanks a lot,

RAF
 
K

Kerem Gümrükcü

Hi RAF,
my question is the following one :
- which XML structure make a node or attribute research faster ?

I dont have performance measures and experience on this
since i never had to read "really" huge xml files. But i think
this also heavily depends on the kind of xml parser you
use. Dont ask me how the System.Xml Parser handles huge
files. I store huge and important things inside a RDBMS like
SQL Server, Oracle, or another proven and stable system
not a xml file,...

Moreover, what should be written as attribute and what should be written as
children node ?

This depends on the extensibillity of your application
and sometimes it is a choice of style. It is sometimes
the same with objects in OO Programming. You will
have a vehicle class, it will have a child object that can be
a car class and it can have attributes like a engine="V6"
and its fuel="leaded" and four tires with attribute brand="bridgestone"
then it can be extended with for seats and they will have the
attributes like material = "leather" or color = "red". I am sure
tthat you understand what i am talking about,...

example:

<vehicle>
<car engine="V6" fuel="leaded" model="muscle car">
<tires count="4" brand="bridgestone">
<seats count="4" material="leather" color="red">
</seats>
</tires>
</car>
</vehicle>

Sure this is a simple example but it show the basic structure
how this can be accomplished. The example can be completely
reorganized but this depends, as i said on the extensibility of
your application and how the "range" of your abstraction should
be and how you want it to be,...


Regards

Kerem

--
 
D

Dubravko Sever

R.A.F. said:
Hi,

When i see a XML file i'm still wondering what are the differences between
writing node data as node attributes or as children nodes.

for example, what are the advantage to write such thing :
<setting>
<client>
<name>Vaporex</name>
<address>Saint Hope st.</address>
</client>
</setting>

instead of :
<setting>
<client name="Vaporex" address="Saint Hope st."></client>
</setting>

my question is the following one :
- which XML structure make a node or attribute research faster ?


Moreover, what should be written as attribute and what should be written
as children node ?
Hi,

It depends,
It could be the same if you planning to use one atrribute with name "name"
(it's simple to read), but in some situation you will have to use multiple
(1..n) as :

<client>
<name>Vaporex</name>
<name>Vaporex123</name>
</client>

Correct me if i'm wrong.

D.S.
 
L

Lew

...
This is an XML question, not a .Net or C# one. Performance is irrelevant;
accuracy of modeling is at issue.

Dubravko said:
It depends,

That's the correct answer.

The choice of sub-node versus attribute boils down to whether the aspect in
question is a modification of a thing, or a new thing in its own right.

In this example, many people would consider the name and address of a client
as first-class information, deserving of their own elements. In my own mind,
I perceive an address as something that can exist independently of an owner.
Saint Hope St. is going to be there whether Vaporex occupies the property or not.

Another distinguisher is that an attribute represents metadata about an
entity, an element represents data.

These are rules of thumb, not the law of the land. Material that I've read
(in XML tutorials and the like) suggest that the decision is often a grey area.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top