This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jnns
Recipients jnns
Date 2022-02-18.10:23:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645179799.58.0.92424391054.issue46786@roundup.psfhosted.org>
In-reply-to
Content
[According to the WHATWG][1], the elements `area`, `base`, `br`, `col`, `embed`, `hr`, `img`, `input`, `link`, `meta`, `param`, `source`, `track`, `wbr` are *void elements* that don't need and therefore shouldn't have a closing tag.

The source view of Firefox 96 shows a warning about an unexpected closing tag [1].

In Python 3.10.2 `xml.etree` seems to correctly recognize most of them as such and doesn't generate closing tags when using the `.tostring()` method. A few elements are serialized with a closing tag (`<embed></embed>` for example). 

```python
from xml.etree import ElementTree as etree

void_elements = [
    "area", "base","br", "col", "embed", "hr", "img", 
    "input", "link", "meta", "param", "source", "track", "wbr"
]
for el in void_elements:
    el = etree.Element(el)
    print(etree.tostring(el, method="html", encoding="unicode"))
```

```html
<area>
<base>
<br>
<col>
<embed></embed>
<hr>
<img>
<input>
<link>
<meta>
<param>
<source></source>
<track></track>
<wbr></wbr>
```

HTML_EMPTY in Lib/xml/etree/ElementTree.py only contains the following entries:

"area", "base", "basefont", "br", "col", "frame", "hr", "img", "input", "isindex", "link", "meta", "param"

I suppose "embed", "source", "track" and "wbr" should be added to that list.  

  [1]: https://html.spec.whatwg.org/multipage/syntax.html#void-elements
  [2]: https://i.stack.imgur.com/rBTHw.png
History
Date User Action Args
2022-02-18 10:23:19jnnssetrecipients: + jnns
2022-02-18 10:23:19jnnssetmessageid: <1645179799.58.0.92424391054.issue46786@roundup.psfhosted.org>
2022-02-18 10:23:19jnnslinkissue46786 messages
2022-02-18 10:23:19jnnscreate