[Expat-discuss] Entity References when there's no DTD

Karl Waclawek karl at waclawek.net
Wed Oct 15 11:25:47 EDT 2003


> Hi,
> 
> Many apologies for just signing up to get a question answered ;-)
> 
> I'm currently trying to produce an XML parser that is able
> to deal with documents which do generally not contain any
> specific DTD sections or references.
> 
> However I'm having a few problems with expat returning
> XML_ERROR_UNDEFINED_ENTITY instead of calling my
> 'skippedEntityHandler' when it encounters entities such as:
> 
> <city>san &#38; jos&eacute; &amp;</city>
> (I want this come out the far end as <city>san & jos&eacute; &</city>)
> 
> But instead it errors - as the DTD has not defined any
> other Entity References (see xmlparse.c:1988) and 'eacute' is
> not a recognised built in entity value.
> (it parses the &#38; and &amp; inside XmlTok() as i'd expected)
> 
> However, what I can't work out is whether this 'error' behaviour is 
> correct as to the XML spec or whether expat is doing 'the wrong thing'(tm)
> in this case?
> 
> There are few lines from about xmlparse.c:1986 which seem to
> require some kind of DTD to have been defined before the
> 'skippedEntityHandler' will be called... anyone have any ideas?!

If I remember correctly, the skippedEntityHandler will only
be called if it is not an error when an entity reference is encountered
for which no entity has been declared. This can happen for a non-validating 
parser like Expat, but not for a validating one.

If it is an error, then an error will be returned.

This is the comment in expat.h:

/* This is called in two situations:
   1) An entity reference is encountered for which no declaration
      has been read *and* this is not an error.
   2) An internal entity reference is read, but not expanded, because
      XML_SetDefaultHandler has been called.
   Note: skipped parameter entities in declarations and skipped general
         entities in attribute values cannot be reported, because
         the event would be out of sync with the reporting of the
         declarations or attribute values
*/

Karl





More information about the Expat-discuss mailing list