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]
Re: [xml-dev] Why is an attribute used to name/identify a chunk ofmarkup?

Primarily (d). Making an identifier an attribute rather than a child element is a convention. One can justify it on the basis that attributes are less powerful than elements (they can't repeat, they have no order, and their values are simple strings) and there's some kind of logic in using a construct that has all the power you need and no more. It also makes the identifier stand out for the human reader.

Michael Kay
Saxonica



On 26 Feb 2022, at 20:20, Roger L Costello <costello@mitre.org> wrote:

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