[Project_owners] Allowed characters on DTDs

Gerald Vogt vogt at spamcop.net
Mon Nov 14 19:43:49 EST 2005


Luca Minuti wrote:
> I use DTDs to store localizable strings. But I noticed that firefox
> doesn't load DTDs if an entity contains percent symbol. Eg:
> 
> <!ENTITY test.percent "%" >
> 
> I know that if a write that:
> 
> <!ENTITY test.percent "&#37;" >
> 
> it works. But my question is... why?

Short answer. '%' is a special character just like "&" in XML.

Long answer: From XML 1.1 http://www.w3.org/TR/2004/REC-xml11-20040204/

[70] EntityDecl ::= GEDecl | PEDecl
[71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
[72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
[73] EntityDef ::= EntityValue| (ExternalID NDataDecl?)
[74] PEDef ::= EntityValue | ExternalID

You have a GEDecl there. Entity Value is:

[9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' |  "'" 
([^%&'] | PEReference | Reference)* "'"

So basically % and & have special meanings in EntityValue, because:

[69] PEReference ::= '%' Name ';'

and

[Definition: Parameter-entity references use percent-sign (%) and 
semicolon (;) as delimiters.]

To elaborate a little bit more:

[Definition: General entities are entities for use within the document 
content. In this specification, general entities are sometimes referred 
to with the unqualified term entity when this leads to no ambiguity.] 
[Definition: Parameter entities are parsed entities for use within the DTD.]

Thus: General entities are entities used in the document and are defined 
as GEDecl in [71]. Parameter entities are used in DTD and defined in [72].

And two examples:

<!ENTITY % YN '"Yes"' >
<!ENTITY WhatHeSaid "He said %YN;" >

and:

<!ENTITY % pub    "&#xc9;ditions Gallimard" >
<!ENTITY   rights "All rights reserved" >
<!ENTITY   book   "La Peste: Albert Camus,
&#xA9; 1947 %pub;. &rights;" >

In the second example entity "book" will be

"La Peste: Albert Camus,
© 1947 Éditions Gallimard. &rights;"

Does that help?? ;-)

Gerald


More information about the Project_owners mailing list