-
XML - using attributes instead of elements
Hello,
is there considerations for subj.? because it is possible to get *the same*
result in two diffrent ways, for example,
<acc>
<usr> guest </usr>
<psw> qwerty </usr>
</acc>
OR
<acc usr="guest" psw="qwerty" />
It clear that second is shorter , but what about
1. performance issues? Faster to work with elements or attributes?
2. easier to work with ADO recordsets?
3. validation facility of attribute or element text (XML Schema)?
4. other ?
may be about this are some articles on internet?
regards,
Mihails
-
Re: XML - using attributes instead of elements
Although attributes are shorter as ASCII they end up as virtually the same
thing once loaded in the DOM.
The advantage of elements is that you can "evolve" your XML schema to replace
the simple typed value of an element to be an XML structure that resolves
itself to be the typed value (i.e be extensible)
Say
<acc>
<usr> guest </usr>
<psw> qwerty </usr>
</acc>
Could become
<acc>
<usr>
<lookup>
<database>MyDatabase</database>
<key>42</key>
</lookup>
</usr>
<psw> qwerty </psw>
</acc>
Dean
"Mihails" <sliahim@my-deja.com> wrote:
>
>Hello,
>
>is there considerations for subj.? because it is possible to get *the same*
>result in two diffrent ways, for example,
>
><acc>
> <usr> guest </usr>
> <psw> qwerty </usr>
></acc>
>
>OR
>
><acc usr="guest" psw="qwerty" />
>
>It clear that second is shorter , but what about
>1. performance issues? Faster to work with elements or attributes?
>2. easier to work with ADO recordsets?
>3. validation facility of attribute or element text (XML Schema)?
>4. other ?
>
>may be about this are some articles on internet?
>
>regards,
>Mihails
-
Re: XML - using attributes instead of elements
yes, Dean, it is that elements are more extensible technique (in case we need
to go one level below)
something about this topic from:
http://www.w3schools.com/xml/xml_attributes.asp
**************************************************************
Use of Elements vs. Attributes
Data can be stored in child elements or in attributes.
Take a look at these examples:
<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
<person>
<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
In the first example sex is an attribute. In the last, sex is a child element.
Both examples provide the same information.
There are no rules about when to use attributes, and when to use child elements.
My experience is that attributes are handy in HTML, but in XML you should
try to avoid them. Use child elements if the information feels like data.
**************************************************************
is there other experience?
Mihails
"Dean Genner" <dean@ceanet.com.au> wrote:
>
>Although attributes are shorter as ASCII they end up as virtually the same
>thing once loaded in the DOM.
>
>The advantage of elements is that you can "evolve" your XML schema to replace
>the simple typed value of an element to be an XML structure that resolves
>itself to be the typed value (i.e be extensible)
>
>Say
>
><acc>
> <usr> guest </usr>
> <psw> qwerty </usr>
></acc>
>
>Could become
>
><acc>
> <usr>
> <lookup>
> <database>MyDatabase</database>
> <key>42</key>
> </lookup>
> </usr>
> <psw> qwerty </psw>
></acc>
>
>Dean
>
>"Mihails" <sliahim@my-deja.com> wrote:
>>
>>Hello,
>>
>>is there considerations for subj.? because it is possible to get *the same*
>>result in two diffrent ways, for example,
>>
>><acc>
>> <usr> guest </usr>
>> <psw> qwerty </usr>
>></acc>
>>
>>OR
>>
>><acc usr="guest" psw="qwerty" />
>>
>>It clear that second is shorter , but what about
>>1. performance issues? Faster to work with elements or attributes?
>>2. easier to work with ADO recordsets?
>>3. validation facility of attribute or element text (XML Schema)?
>>4. other ?
>>
>>may be about this are some articles on internet?
>>
>>regards,
>>Mihails
>
-
Re: XML - using attributes instead of elements
I personally always try to use 'Element Centric' XML. I find that it makes
documents easier to follow, and as has been already mentioned allows extending
the document easier. I have also heard that element based XML is more efficient
to process with XPath queries, although I have not checked this myself.
The one exception I make is when dealing with metadata, ie data about data
such as ID numbers, reference numbers, types and other data which although
important to the system, may be fairly meaningless to a person.
eg
<Customer id="3212"> Dave Jones</Customer>
or maybe
<Area type="County">Hampshire</Area>
-
Re: XML - using attributes instead of elements
All the other replies are great, but here is something else to consider:
Suppose that you have a document which you do not need to reatain in memory.
All you want to do is scan it, get the data and move on with your life.
Using SAX API will speed things up a bit for you and guess what? Parsing
Attributes with SAX is easier than parsing nested Elements because you don't
have to worry as much about nesting location.
So if you don't need the extensibility of the element and want to use SAX
parser, you may prefer Attributes.
- vlad -
-----------------------------------------------
"Carl Gregory" <carl.gregory@hants.gov.uk> wrote:
>
>I personally always try to use 'Element Centric' XML. I find that it makes
>documents easier to follow, and as has been already mentioned allows extending
>the document easier. I have also heard that element based XML is more efficient
>to process with XPath queries, although I have not checked this myself.
>The one exception I make is when dealing with metadata, ie data about data
>such as ID numbers, reference numbers, types and other data which although
>important to the system, may be fairly meaningless to a person.
>eg
><Customer id="3212"> Dave Jones</Customer>
>
>or maybe
>
><Area type="County">Hampshire</Area>
>
-
Re: XML - using attributes instead of elements
http://www.xfront.com/BestPracticesHomepage.html
Here is a link to a resource concerning Schema best practices. While it doesn't
provide a clear cut attribute/element answer, it does give some information
about the decision making process.
As I see it this is largely an academic debate. Both forms of a schema, attribute
vs. element based, define an XML document with the same information. Your
specific needs in processing the resulting document should drive your decision.
Here's my 2 cents:
1. I use a mixture. One of the arguments I have heard is the elements are
more extensible and allow you to evolve your schema. While this is true,
a distinct needs to be made between extensible and evolving. I liken extensible
to the inheritance and polymorphism in the OO word, the schema can represent
more than one object. I don't like saying evolve, because my experience with
this word is that due diligence has not been paid in the analysis/requirements/architecture
and we're not sure what our ultimate goal is.
2. Elements are more readable, but I don't really care. It is a very rare
occurence that I will show a raw XML document without applying some transformation
to it. Attributes are more cryptic, but in the work I have had to do they
make for simpler XSL. Attributes also provide a cross-over for people new
to XML since they can usually be mapped to fields of a record for database
developers. Typically, I have used XML to transfer data between things, totally
in the background with no UI. This is one of XML's touted benefits, communications
between hetereogenous environments/systems.
3. I am not aware of any definitive performance numbers that clearly show
one technique is superior to another.
Utlimately, the decision is based on you and your development teams comfort
level, impact on team, future maintenance costs, and performance requirements.
Raj
3.
"Mihails" <sliahim@my-deja.com> wrote:
>
>yes, Dean, it is that elements are more extensible technique (in case we
need
>to go one level below)
>
>something about this topic from:
>http://www.w3schools.com/xml/xml_attributes.asp
>**************************************************************
>Use of Elements vs. Attributes
>Data can be stored in child elements or in attributes.
>
>Take a look at these examples:
><person sex="female">
> <firstname>Anna</firstname>
> <lastname>Smith</lastname>
></person>
>
>
><person>
> <sex>female</sex>
> <firstname>Anna</firstname>
> <lastname>Smith</lastname>
></person>
>
>
>In the first example sex is an attribute. In the last, sex is a child element.
>Both examples provide the same information.
>
>There are no rules about when to use attributes, and when to use child elements.
>My experience is that attributes are handy in HTML, but in XML you should
>try to avoid them. Use child elements if the information feels like data.
>**************************************************************
>
>is there other experience?
>
>Mihails
>
>"Dean Genner" <dean@ceanet.com.au> wrote:
>>
>>Although attributes are shorter as ASCII they end up as virtually the same
>>thing once loaded in the DOM.
>>
>>The advantage of elements is that you can "evolve" your XML schema to replace
>>the simple typed value of an element to be an XML structure that resolves
>>itself to be the typed value (i.e be extensible)
>>
>>Say
>>
>><acc>
>> <usr> guest </usr>
>> <psw> qwerty </usr>
>></acc>
>>
>>Could become
>>
>><acc>
>> <usr>
>> <lookup>
>> <database>MyDatabase</database>
>> <key>42</key>
>> </lookup>
>> </usr>
>> <psw> qwerty </psw>
>></acc>
>>
>>Dean
>>
>>"Mihails" <sliahim@my-deja.com> wrote:
>>>
>>>Hello,
>>>
>>>is there considerations for subj.? because it is possible to get *the
same*
>>>result in two diffrent ways, for example,
>>>
>>><acc>
>>> <usr> guest </usr>
>>> <psw> qwerty </usr>
>>></acc>
>>>
>>>OR
>>>
>>><acc usr="guest" psw="qwerty" />
>>>
>>>It clear that second is shorter , but what about
>>>1. performance issues? Faster to work with elements or attributes?
>>>2. easier to work with ADO recordsets?
>>>3. validation facility of attribute or element text (XML Schema)?
>>>4. other ?
>>>
>>>may be about this are some articles on internet?
>>>
>>>regards,
>>>Mihails
>>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks