all Python 3xml.etree.ElementTreefunction
xml.etree.ElementTree.iselement()
tree and elements
Checks whether an object looks like a tree element: True for Element and its subclasses, False for strings and ElementTree.
Syntax
ET.iselement(element)
The check is duck-typed: True for any object with a tag attribute, not only for Element instances. An ElementTree wrapper does not count as an element; call getroot() first. For a strict type check use isinstance(x, ET.Element).
Examples
import xml.etree.ElementTree as ET
root = ET.fromstring('<a/>')
print(ET.iselement(root), ET.iselement('<a/>')) # → True False
print(ET.iselement(ET.ElementTree(root))) # → False
class Fake:
tag = 'x'
print(ET.iselement(Fake())) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy