When you are working with multiple namespaces, the QName object is useful for combining the
“namespace URI” part with the “local
name” part. A QName instance can
be used for the name part of attributes that are in a
different namespace than their containing element.
Although it is not legal in XML element names, there is a convention called “Clark notation” (after James Clark) that combines these two parts in a string of this form:
{nsURI}local
To construct a new QName instance, use a
statement of this general form:
etree.QName(text, tag=none)
If the fully qualified element name is already in
Clark notation, call the QName
constructor with this argument alone.
If you would like to pass the namespace URI and the
local name separately, call QName
with the namespace URI as the text
argument, and the local name as the tag argument.
Here are two examples for creating a QName
instance representing a qualified name in the XSLT
namespace with a local name of template:
In Clark notation:
qn = etree.QName("{http://www.w3.org/1999/XSL/Transform}template")
With the namespace URI and local name supplied separately:
qn = etree.QName("http://www.w3.org/1999/XSL/Transform", "template")