Re: Is markup allowed in attribute values?

Paul Prescod (papresco@calum.csclub.uwaterloo.ca)
Thu, 27 Jun 1996 10:39:21 -0400


Message-Id: <1.5.4.32.19960627143921.006d7e70@csclub.uwaterloo.ca>
Date: Thu, 27 Jun 1996 10:39:21 -0400
To: murray@spyglass.com (Murray Altheim),
From: Paul Prescod <papresco@calum.csclub.uwaterloo.ca>
Subject: Re: Is markup allowed in attribute values?
Cc: amc@cs.wustl.edu (Adam M. Costello), www-html@w3.org

At 08:01 PM 6/26/96 -0500, Murray Altheim wrote:
>First, note that not all attributes are declared CDATA. I'm not sure what
>you mean by "sometimes" entities. Most HTML attributes can contain
>entities; the question is whether or not they will be processed (ie.,
>replaced).

I'm getting confused by this discussion, so let me see if I can clarify.
_ALL_ SGML/HTML attributes may have entity references in them. _ALL_
SGML/HTML attributes allow entity expansion/processing/replacement (choose
your favourite term). Whenever I feel I am in danger of forgetting this, I
try to parse a sample document I made months ago to test an SGML editor's
conformance:

<!DOCTYPE ROOT [
<!ELEMENT ROOT o o (foo, bar, baz, blart ) >

<!-- Elements to test out different attribute types -->
<!ELEMENT foo  - o EMPTY >
<!ATTLIST foo    num NUMBER  #IMPLIED>
<!ELEMENT bar  - o EMPTY >
<!ATTLIST bar     id ID      #IMPLIED>
<!ELEMENT baz  - o EMPTY >
<!ATTLIST baz     cd CDATA   #IMPLIED>
<!ELEMENT blart  - o EMPTY >
<!ATTLIST blart     nm NAME   #IMPLIED>

<!-- Entities to replace -->
<!ENTITY nument CDATA "123">
<!ENTITY ident  CDATA "anid">
<!ENTITY cdataent CDATA "Some Cdata">
<!ENTITY nment CDATA "ANAME" >
]>
<foo num="&nument">
<bar id="&ident;">
<baz cd="&cdataent;">
<blart nm="&nment;">

This document _will_ validate correctly (try it!) because the entities _are_
replaced. The reason many people believe that they are not is because of the
unfortunate overloading of the keyword "CDATA" in different contexts. In
attributes it means that the content is "character data". But that
"character data" behaves as "replacable character data" does in element
content context.

So, as I understand it, entity markup is _always_ allowed in attributes.
Less than and greater than symbols are _never_ interpreted as markup within
attributes (just as they are not in "replacable character data) so it is
impossible to put elements in attributes although it is possible (in fact
quite easy) to put less than and greater than characters in attributes.

 Paul Prescod