[Expat-discuss] Manage unknown entityes?

Karl Waclawek karl at waclawek.net
Thu Mar 6 09:14:02 EST 2003



> How can I manage unknown entities?
> 
> When parsing the following xml file I get the error: "undefined entity
> at line 7" and the parser stops.
> 
> --------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE doc [
>    <!ELEMENT doc ANY>
>    <!ELEMENT para (#PCDATA)>
> ]>
> <doc>
>     <para>Hello World&iquest;</para>
> </doc>
> --------------------
> 
> The &iquest; entity is one of the standard SGML character entities
> defined in ISOPub, but unknown by the expat parser.

This is not a pre-defined entity in XML and requires a declaration.
Your document is simply not well-formed and will be rejected
by any compliant XML parser.

> I know that I could solve this by adding an entity declaration, but very
> often users asssume that a parser have a knowledge about all the ISO
> defined entities.

In XML that is an incorrect assumption.
 
> Is it possible to set up a callback where I can handle unknown entities
> where I can deside myself if I want the parser to terminate or simply
> return the correct UTF-8 code if my callback know the entity?

We don't have such a call-back, and it really is not a good idea
since it encourages the creation of non-wellformed (malformed?) documents.

Karl



More information about the Expat-discuss mailing list