Confused about & in entity literal

Richard Tobin richard at cogsci.ed.ac.uk
Sat May 8 01:31:24 BST 1999


>   <!DOCTYPE doc [
>   <!ELEMENT doc (#PCDATA)>
>   <!ENTITY e "<![CDATA[&foo;]]>">
>   ]>
>   <doc>&e;</doc>

Hmmm, this one *is* a little strange.  Let's consider the other one
first:

>   <!DOCTYPE doc [
>   <!ELEMENT doc (#PCDATA)>
>   <!ENTITY e "&lt;foo>">
>   ]>
>   <doc>&e;</doc>

The &lt; is *not* expanded when the entity is defined.  It is a
general entity (that it's built-in makes no difference) and is
"bypassed" in the terminology of section 4.4.  So it's just as if
the body had been 

  <doc>&lt;foo></doc>

which is perfectly well-formed.

Back to the first example.  What's strange about it is that I believe
that

  <!ENTITY e "<![CDATA[&foo]]>">

(note the missing semicolon) would not be well-formed, even though
there turns out not to be an entity reference when it is expanded in
the body!  In the original, &foo; is (by production 9) an entity
reference when it appears in the entity definition (and it is
bypassed), but is not an entity reference when it is parsed in
the body.

-- Richard

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list