New submission from py.user: It is possible to create and serialize an Element instance with empty string tag value:
>>> import xml.etree.ElementTree as etree >>> >>> root = etree.Element('') >>> elem = etree.SubElement(root, '') >>> >>> root <Element '' at 0xb744e34c> >>> elem <Element '' at 0xb744e374> >>> >>> etree.tostring(root) b'<>< /></>' >>> etree.dump(root) <>< /></> >>> It is possible to create and serialize an Element instance with None tag value: >>> import xml.etree.ElementTree as etree >>> >>> root = etree.Element(None) >>> elem = etree.SubElement(root, None) >>> >>> root <Element None at 0xb7468c34> >>> root[0] <Element None at 0xb746334c> >>> len(root) 1 >>> etree.tostring(root) b'' >>> etree.dump(root) >>> And same try with site package lxml raises an exception both for empty string and for None: >>> import lxml.etree >>> >>> lxml.etree.Element('') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lxml.etree.pyx", line 2809, in lxml.etree.Element (src/lxml/lxml.etree.c:61393) File "apihelpers.pxi", line 87, in lxml.etree._makeElement (src/lxml/lxml.etree.c:13390) File "apihelpers.pxi", line 1446, in lxml.etree._getNsTag (src/lxml/lxml.etree.c:25978) File "apihelpers.pxi", line 1481, in lxml.etree.__getNsTag (src/lxml/lxml.etree.c:26304) ValueError: Empty tag name >>> >>> lxml.etree.Element(None) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lxml.etree.pyx", line 2809, in lxml.etree.Element (src/lxml/lxml.etree.c:61393) File "apihelpers.pxi", line 87, in lxml.etree._makeElement (src/lxml/lxml.etree.c:13390) File "apihelpers.pxi", line 1446, in lxml.etree._getNsTag (src/lxml/lxml.etree.c:25978) File "apihelpers.pxi", line 1464, in lxml.etree.__getNsTag (src/lxml/lxml.etree.c:26114) File "apihelpers.pxi", line 1342, in lxml.etree._utf8 (src/lxml/lxml.etree.c:24770) TypeError: Argument must be bytes or unicode, got 'NoneType' >>> ---------- components: Library (Lib), XML messages: 277125 nosy: py.user priority: normal severity: normal status: open title: In xml.etree.ElementTree Element can be created with empty and None tag type: behavior versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28236> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com