Re: XML entity question

> What happens if someone has the following in their DTD:
> 
> <!ENTITY DTDVersion 'v2.0N'>
> <!ELEMENT Module (#PCDATA)*>
> <!ATTLIST Module
>   DTDVersion CDATA #FIXED "&DTDVersion;"
> > 
> 
> Then exactly what (non-null) value should be assigned to
> the DTDVersion attribute on the Module element in an 
> instance for the instance to be valid?
> 
> The table in "4.4 XML Processor Treatment of Entities and 
> References" <http://www.w3.org/TR/REC-xml/#entproc> has
> one row for "Reference in DTD" and another for "Reference
> in Attribute Value".

"Reference in Attribute Value" says "as a reference within either the
value of an attribute in a start-tag, or a default value in an
attribute declaration", which applies here.

"Reference in DTD" says "... but outside of an ... AttValue ...", so
it does not apply (the default value is an AttValue, see prod [60]).

> That would imply that a general entity reference within
> an attribute decl within a DTD is governed by "4.4.5 
> Included in Literal" <http://www.w3.org/TR/REC-xml/#inliteral>
> which says "When an entity reference appears in an attribute 
> value...its replacement text MUST be processed in place of 
> the reference itself as though it were part of the document 
> at the location the reference was recognized...."  But the
> phrase "part of the document" confuses me since we are talking
> about a DTD.  When does the entity reference get replaced?

It is replaced when the default value is parsed, so the default
value of the attribute is "v2.0N".

> Now, suppose instead the DTD reads:
> 
> <!ENTITY % DTDVersion 'v2.0N'>
> <!ELEMENT Module (#PCDATA)*>
> <!ATTLIST Module
>   DTDVersion CDATA #FIXED "%DTDVersion;"
> > 
> 
> Back to the table, do I now use the "Reference in DTD" or 
> "Reference in Attribute Value" row?

Again, it's a "Reference in Attribute Value", but in this case the
table gives "Not recognized" for parameter entities in that case.  (So
it wasn't really a reference at all.)  The default value will be
"%DTDVersion;" which is not what you want.

> If the former, then I'm looking at "4.4.8 Included as PE" 
> <http://www.w3.org/TR/REC-xml/#as-PE> which says "When a 
> parameter-entity reference is recognized in the DTD and 
> included, its replacement text MUST be enlarged by the 
> attachment of one leading and one following space (#x20) 
> character...."  But that doesn't seem to make sense in
> this case.  Spaces aren't really going to be added here,
> are they?

The "Included as PE" case only applies when the reference is in
the DTD but not in a quoted string.

-- Richard

Received on Thursday, 30 August 2007 15:28:23 UTC