all Python 3xml.etree.ElementTreeterm
xml.etree.ElementTree.QName
namespaces
A wrapper for a qualified name {uri}local: lets you give a namespaced tag or attribute value as a separate URI and local name.
Syntax
q = ET.QName(text_or_uri, tag=None)
ElementTree stores names in Clark notation '{uri}local', and QName merely builds it from two parts: .text holds that same string. It helps when an attribute value is itself a prefixed name (xsi:type), so the prefix gets declared on output. A QName compares to a string by .text, but elem.tag after parsing is a plain str, not a QName.
Examples
import xml.etree.ElementTree as ET
q = ET.QName('http://ex.com/ns', 'item')
print(q.text, q == '{http://ex.com/ns}item') # → {http://ex.com/ns}item True
e = ET.Element(q)
print(ET.tostring(e, encoding='unicode')) # → <ns0:item xmlns:ns0="http://ex.com/ns" />
See also
Open in the full glossarydocs.python.orgReport an inaccuracy