XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Why is an attribute used to name/identify a chunk of markup?

Hi Folks,

An XSLT function is XML. XSLT functions are expressed this way:

    <xsl:function name="f:my-function">

        <!-- do something -->

    </xsl:function>

It has an element, function, which is bound to the XSLT namespace. It has an attribute, name. The purpose of the name attribute is to name the function (i.e., name a chunk of markup).

Why did they (the XSLT working group) design the XML that way? Specifically, why did they use an attribute for providing the name of the function? Why didn’t they use an element:

    <xsl:function>
        <name>f:my-function</name>

        <!-- do something -->

    </xsl:function>

An XML Schema element declaration is XML. Element declarations are expressed this way:

    <xs:element name="Book">

        <!-- declare it -->

    </xs:element>

Why did they (the XML Schema working group) design the XML that way? Specifically, why did they use an attribute for providing the name of the element? Why didn’t they use an element:

    <xs:element>
        <name>Book</name>

        <!-- declare it -->

    </xs:element>

An XML RDF document is XML. RDF items are expressed this way:

    <River rdf:ID="Yangtze">

        <!-- describe something -->

    </River>

Why did they (the RDF working group) design the XML that way? Specifically, why did they use an attribute for providing the identity of the item? Why didn’t they use an element:

    <River>
        <rdf:ID>Yangtze</rdf:ID>

        <!-- describe something -->

    </River>

In each case the XML was designed using an attribute rather than an element. Why? Which of these is the reason:

  1. The choice of using an attribute rather than element was completely arbitrary.
  2. They wanted to save a few bytes, so they used an attribute rather than an element.
  3. Attributes have scope. The scope is from the start tag to the matching end tag. So in <xsl:function name="f:my-function"> the name applies from <xsl:function> to </xsl:function>. That is, the name applies over the whole function. That’s exactly what we want, for the name to apply over the whole chunk of markup. Conversely, if an element had been used, <name>f:my-function</name>, it does not have scope over the entire function. Ditto for the XML Schema example and the RDF example.
    [Before you tell me: “The XML specification says nothing about attributes having scope.” I know. However, there is strong empirical evidence that XML developers and users *do* treat attributes as having an implied scope.]
  4. It is a convention among XML developers and users to use an attribute to name/identify a chunk of markup.
  5. Other (what?)

/Roger

 



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS