Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

XML attributes or node ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
R.A.F. - 25 Nov 2007 18:46 GMT
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
Kerem Gümrükcü - 25 Nov 2007 20:27 GMT
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

Signature

-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

Dubravko Sever - 25 Nov 2007 20:34 GMT
> Hi,
>
[quoted text clipped - 19 lines]
> 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.
Lew - 25 Nov 2007 21:33 GMT
"R.A.F." wrote ...
>> 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.
...
>> 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 ?

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

> 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.

>> <setting>
>> <client>
[quoted text clipped - 7 lines]
>> <client name="Vaporex" address="Saint Hope st."></client>
>> </setting>

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.

Signature

Lew


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.