473,320 Members | 1,936 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,320 software developers and data experts.

The age old debate of Attributes vs. Elements

Hi all, I have to decide on an XML structure going forward. The
structure is going to house a large amount of data. In the past I've
always just used the philosophy of "when in doubt use elements" - but
I just read this article:
http://msdn.microsoft.com/library/de...ml02212000.asp

And there is some indication that you will gain performance benefits
from XML that uses attributes rather than elements - example:

<grandparent>
<parent>
<child>
<name>
tony
</name>
</child>
<name>
Sarah
</name>
</parent>
<name>
Tom
</name>
</grandparent>
OR
<grandparent name='Tom'>
<parent name='sarah'>
<child name='tony'>
</child>
</parent>
</grandparent>

Now obviously in the first case you leave it open if you want to have
a deeper structure to name - like firstName, lastName, middleName,
alias, etc.

But if we were to assume that the XML structure will never change (I
know that is unlikely in many scenarios) but if it were to remain the
same, would there likely be a decrease in parsing time when I use the
transform method of XSLTransform (the .NET class) - in addition, I am
passing XPath queries (through a XPathNodeIterator object).

Thanks,
Novice
Nov 12 '05 #1
2 3336
Novice wrote:
<grandparent name='Tom'>
<parent name='sarah'>
<child name='tony'>
</child>
</parent>
</grandparent>

Now obviously in the first case you leave it open if you want to have
a deeper structure to name - like firstName, lastName, middleName,
alias, etc.
The same in the second one - what's wrong with firstName attribute?
But if we were to assume that the XML structure will never change (I
know that is unlikely in many scenarios) but if it were to remain the
same, would there likely be a decrease in parsing time when I use the
transform method of XSLTransform (the .NET class) - in addition, I am
passing XPath queries (through a XPathNodeIterator object).


Well, querying attributes is probably faster than child nodes, but large
attribute collection isn't good idea either.
I don't think there is any substantial difference. Do it as you feel
better for you.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2
I think the choice between using attributes vs. elements should be based on
the semantics of the data rather than the performance aspect.

I remember reading an article that provided a guideline for using attributes
vs. elements and it was something like use attributes for metadata for the
element node and elements for the actual content.
I am probably bastardizing the originally elegantly put statement here but
you get the gist. The author also mentioned and I agree that the line
between what is metadata and data isn't all that clear always. So you
should use your judgement.

For your example, I guess something like a person's names or SSN may be a
good fit for attributes whereas, what kind of car they drive and where they
live clearly works better as elements.
Just my 2 cents!

Jiho Han

"Novice" <6t**@qlink.queensu.ca> wrote in message
news:b8*************************@posting.google.co m...
Hi all, I have to decide on an XML structure going forward. The
structure is going to house a large amount of data. In the past I've
always just used the philosophy of "when in doubt use elements" - but
I just read this article:
http://msdn.microsoft.com/library/de...ml02212000.asp
And there is some indication that you will gain performance benefits
from XML that uses attributes rather than elements - example:

<grandparent>
<parent>
<child>
<name>
tony
</name>
</child>
<name>
Sarah
</name>
</parent>
<name>
Tom
</name>
</grandparent>
OR
<grandparent name='Tom'>
<parent name='sarah'>
<child name='tony'>
</child>
</parent>
</grandparent>

Now obviously in the first case you leave it open if you want to have
a deeper structure to name - like firstName, lastName, middleName,
alias, etc.

But if we were to assume that the XML structure will never change (I
know that is unlikely in many scenarios) but if it were to remain the
same, would there likely be a decrease in parsing time when I use the
transform method of XSLTransform (the .NET class) - in addition, I am
passing XPath queries (through a XPathNodeIterator object).

Thanks,
Novice

Nov 12 '05 #3

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

Similar topics

1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
2
by: Stewart Johnson | last post by:
Hey All - I'm stuck while trying to write a schema, hoping someone can provide me with a flash of inspiration. One of the elements I'm writing has two attributes, both of which are optional....
9
by: Joris Gillis | last post by:
Hi everyone, I was wondering... Can one element have multiple (identically named) attributes in XML? e.g. Is the following document valid XML? <?xml version="1.0" encoding="UTF-8"?> <root...
9
by: Soren Kuula | last post by:
Hi, I just can't find namespaces of attributes stated clearly enough in the XML namespace spec. But .. I hear rumors that attributes, unless qualified otherwise, default to the namespace of the...
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>
3
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ...
1
by: Tod Johnson | last post by:
Hello all, Can't figure it out. :( Assume that we have 2 XML document: Document1 (source): <elements> <elementA attribute1="value1" attribute2="value2" ... /> <elementA attribute1="value1"...
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>...
0
by: David Lozzi | last post by:
Howdy, I just had a small explosion in my brain, and now i'm a little more confused than I was before. I'm fairly new to XML, but understand it for the most part in regards to formatting. I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.