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

Re: element content vs. element attribute

  • From: Liam Quin <liamquin@i...>
  • To: xml-dev@i...
  • Date: Sun, 21 Dec 1997 04:09:27 -0500 (EST)

element attribute
On Sat, 20 Dec 1997, Ray Waldin asked:

> when should data be contained by elements?  Or conversely, when should
> data be an attribute of an element instead of contained by that element? 

There are a number of issues that may help here, depending on how the
information is going to be used...

Some pragmatics first:

* it's often easiest for people writing ad-hoc parsers if you only use
  elements; there's only one syntax to handle

* if you will ever need to have more complex structured values with markup
  in them, they will need to be in element content, because XML (like SGML)
  has a restriction that you can't put element markup inside attributes

* if you want the information to be displayed in XML or HTML or SGML browsers
  most or all of the time, use content, as the style sheets are generally
  less flexible with attributes.

* it's relatively easy to strip out all attribute values and make a
  pared-down instance, if that's useful

* attributes are good for things like interpretations of a text by someone
  transcribing it, not part of actual content

A philosophical view:

* attributes may be used for annotating the element tree; in other words,
  you could use them to store element properties.
  for example,
    <boiler MinTemperature="7" MaxTemperature="320">
	steam
	water
	gunk
    </boiler>
  Unfortuantely, a practical example would add units and tolerance to
  the temperature, and then you need to use elements or a non-XML sub-
  structure:
    <boiler MinTemperature="7 {units K} {tolerance {plus 3} {minus 2}"....>
  This is generally unsatisfactory because it's not using XML; so
    <boiler>
      <MinTemperature
	<unit ref="SIUnits#Kelvin" abbr="K">Kelvin</unit>
	<value plus="3" minus="2">7</value>
      </MinTemperature>
    </boiler>

Clearly you could take those items i have left as attributes and turn
them into elements, and in fact any element E with attribute list A and
content model C can be converted into an element E' with content model
    E.atts(A), E.content(E)
e.g.
    <!Element Boiler-prime
	(Boiler-prime-attributes, Boiler-prime-content)
    >

    <!Element Boiler-prime-attributes
	(
	  MinTemperature-prime,
	  MaxTemperature-prime
	)
    >

    <!Element Boiler-prime-content
	(steam-prime, water-prime, gunk-prime)
    >

It is therefore possible to think of attributes as syntactic sugar for
a very restricted kind of content model.

Unfortunately, this is not quite correct, because XML attributes support
a set of constraints on their content which is entirely different to
that supported for elements.

If you only ever use CDATA, ID and name group attributes, retain ID
attributes as attributes, and convert name group token lists to
corresponding empty elements, the conversion still applies.

In theory, then, attributes are a useful but limited shrthand in most
cases, but, essential for IDref and other cases that are not supported
in element content.

In practice, they can be used to make an instance more readable, or to
reduce file size, or to distinguish between different sorts of information.

Hope this helps.

Lee (tired at 4 am!)

-- 
Liam Quin --  the barefoot typographer -- Toronto
lq-text: freely available Unix text retrieval
IRC: Learn about XML/SGML/XSL/XLL/DSSSL on irc.dragonnet.org in #xml
email address: l i a m q u i n, at host: i n t e r l o g  dot  c o m


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i...
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@i... the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@i... the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@i...)


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.