[XML-SIG] Handling of character entity references

Mark E. snowball3@softhome.net
Mon, 26 May 2003 19:08:12 -0400


Randall Nortman wrote:

> On Mon, May 26, 2003 at 01:54:10PM -0400, Mark E. wrote:
> 
>>Randall Nortman wrote:
>>
>>>On Mon, May 26, 2003 at 09:46:14AM -0400, Mark E. wrote:
>>
>>>Everything parsed fine, but "é" was translated to nothing (no
>>>character in that spot at all) on output. I suspect the skippedEntity
>>>method needs to actually *do* something other than just print that it
>>>is skipping an entity
>>
>>I'm not familiar with the DOM part of pyxml, but from a quick 
>>examination of the DOM code, it seems to me like the skippedEntity 
>>handler should create a "entity reference" object and add it to the 
>>document.
> 
> 
> Well, I dug around until I figured out how XmlDomGenerator works, and
> the following code was what was necessary:
> 
>     def skippedEntity(self, name):
>         """Found an undefined entity. Preserve it here."""
>         self._completeTextNode()
>         self._nodeStack[-1].appendChild(self._ownerDoc\
>                                         .createEntityReference(name))
> 
> The rest of the code was essentially as you had provided. Of course,
> my DOCTYPE section. I suspect this is due to the feature_external_ges
> and UseForeignDTD magic you performed in your example, which I do not
> fully understand.

UseForeignDTD is documented xml-ref.txt. feature_external_ges is 
document in the Python docs (including 
http://www.python.org/doc/current/lib/module-xml.sax.handler.html).

 >This behavior is OK for now, but what if I actually
> want to enable some entities to be parsed and substituted in the
> future?

The problem is that PyXML and UseForeignDTD(true) are currently 
incompatible unless feature_external_ges is turned off. You can 
experience the problem firsthand by commenting out the line in my 
original sample that turns off feature_external_ges.

Mark