[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: attributes vs. elements


xml attribute vs element


> -----Original Message-----
> From: mgushee@h... [mailto:mgushee@h...] 
> Sent: Tuesday, September 10, 2002 19:52
> To: xml-dev@l...
> Subject: Re:  attributes vs. elements
> 
> 
> On Tue, Sep 10, 2002 at 01:21:37PM -0400, Maciejewski, Thomas wrote:
> > This is sort of a newbie question but one that I never 
> fully understood or
> > maybe just don't know how to explain it to others. 
> > 
> > When should one use an element and when should one use an attribute?
> 
> That's a very common and very important question, and it's probably in
> a FAQ somewhere, but I have no idea which FAQ. In any case, 
> there is no
> hard and fast answer to that question.
> 
> The traditional distinction between elements and attributes 
> is that the
> former are for content (information of interest to the end user or the
> consuming application) and the latter for metadata (information about
> information), and there is no clearcut, universal distinction between
> those two. Generally speaking, the text in a paragraph or the 
> data in a
> database record would be considered content; the date that content was
> last modified will probably be metadata, but it's not hard to imagine
> scenarios where you might want to treat it as content. Ultimately,
> deciding whether something is content or metadata is up to 
> the creators
> and users of the information.
> 
> But back to elements and attributes. Some considerations that 
> may affect
> your choice:
> 
>   * Elements may not have more than one attribute with the same name, 
>     but child element names can be repeated indefinitely (unless 
>     forbidden by a schema, of course).
> 
>   * XML parsers must preserve the order of elements, but not 
> attributes.
> 
>   [ given the above two statements, we can say that in programming
>     terms, the attributes of any given element are analogous to a 
>     hash (AKA mapping, dictionary, etc.), while the child elements 
>     are analogous to an array ]
> 
>   * Attributes can't contain elements--though of course they can
>     reference them.
> 
>   * White space in elements can be preserved, whereas white space in
>     attributes is normalized (leading and trailing spaces are 
> stripped,
>     each extent of internal white space is collapsed to a single space
>     character).

Matt,

I don't follow you.  If the schema is specified in XML Schema and the
datatype of an attribute is "string" (whose "whitespace" facet is
"preserve" by default), I don't believe white space is normalized.  Are
you saying that an attribute of type "string" behaves differently from
an element of type "string" as to white space handling?

Alessandro Triglia



> 
>   * Attributes are more compact, since their names only occur once per
>     instance and they have fewer 'overhead' characters: ="" 
> vs. <> </>.
> 
>   * Many people find elements more readable.
> 
> I think there is a tendency for document-oriented 
> applications to prefer
> elements, and messaging and automated data-exchange applications to
> prefer attributes--the rationale being that bandwidth is more 
> important
> and human-readability less so. However, in cases where 
> human-readability
> is unimportant, you might want to ask whether XML is an appropriate
> solution at all.
> 
> That's my $.02.
> 
> -- 
> Matt Gushee
> Englewood, Colorado, USA
> mgushee@h...
> http://www.havenrock.com/
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
> 
> 


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.