lxml empty versus self closed tag

Dieter Maurer dieter at handshake.de
Thu Mar 3 04:55:04 EST 2022


Robin Becker wrote at 2022-3-3 09:21 +0000:
>On 02/03/2022 18:39, Dieter Maurer wrote:
>> Robin Becker wrote at 2022-3-2 15:32 +0000:
>>> I'm using lxml.etree.XMLParser and would like to distinguish
>>>
>>> <tag></tag>
>>>
>>> from
>>>
>>> <tag/>
>>>
>>> I seem to have e.getchildren()==[] and e.text==None for both cases. Is there a way to get the first to have e.text==''
>>
>> I do not think so (at least not without a DTD):
>
>I have a DTD which has
>
><!ELEMENT tag (content)*>
>
>so I guess the empty case is allowed as well as the self closed.

Potentially, something changes when `content` contains `PCDATA` (as
one possibility) (but I doubt it).


More information about the Python-list mailing list