473,769 Members | 6,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 XPathNodeIterat or object).

Thanks,
Novice
Nov 12 '05 #1
2 3363
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 XPathNodeIterat or 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.que ensu.ca> wrote in message
news:b8******** *************** **@posting.goog le.com...
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 XPathNodeIterat or 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
2722
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 namespace prefix, what is its namespace, if default namespaces do not apply? Are (either of) prefixed or non-prefixed attributes correct? For example, are the following equivalent: <html:br class="foo"...
2
2760
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. I want to express in the schema that there's a relationship between the two -- that the second attribute is optional only if the first one is not specified. ie:
9
1641
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 a="1" a="2" a="3"/> And if it is, how can I create this document with XSLT when this is the input XML?
9
1844
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 owner element. Is that right ? Like:
7
1851
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
9927
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 ========================= <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"
1
4108
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" attribute2="value2" ... /> ...
6
1901
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> <Elements> <Element att1="1" att2="2" att3="3" //Some attributes are
0
1281
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 some XML files I use for populating dropdowns, like a statelist and other options. These are setup in the XML file with attributes. <root> <state name=Massachusetts abb=MA/>
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.