preserving entities with lxml

Robin Becker robin at reportlab.com
Thu Jan 13 04:58:09 EST 2022


On 13/01/2022 09:29, Dieter Maurer wrote:
> Robin Becker wrote at 2022-1-13 09:13 +0000:
>> On 12/01/2022 20:49, Dieter Maurer wrote:
>> ...
>>> Apparently, the `resolve_entities=False` was not effective: otherwise,
>>> your tree content should have more structure (especially some
>>> entity reference children).
>>>
>> except that the tree knows not to expand the entities using ET.tostring so in some circumstances resolve_entities=False
>> does work.
> 
> I think this is a misunderstanding: `tostring` will represent the text character `&` as `&`.

aaahhhh,

thanks I see now. So tostring is actually restoring some of the entities which on input are normally expanded. If that 
means resolve_entities=False does not work at all then I guess there's no need to use it at all. The initial transform

& --> &

does what I need as it is reversed on output of the tree fragments.

Wonder what resolve_entities is actually used for then? All the docs seem to say

> resolve_entities - replace entities by their text value (default: True)

I assumed False would mean that they would pass through the parse
--
Robin Becker



More information about the Python-list mailing list