lxml empty versus self closed tag

Dieter Maurer dieter at handshake.de
Wed Mar 2 13:39:24 EST 2022


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):
`<tag/>' is just a shorthand notation for '<tag></tag>' and
the difference has no influence on the DOM.

Note that `lxml` is just a Python binding for `libxml2`.
All the parsing is done by this library.


More information about the Python-list mailing list