Skip to content
Search

QName

lastmod 2024-01-09created 2021-10-134 edits

Qualified names (QNames): a QName consists of an optional namespace prefix and a local name. An expanded QName contains a namespace URI and a local name. Two QNames are equal if their namespace URIs and local names are the same.

Purpose

Because URI references can be long and may contain characters that are prohibited in element/attribute naming, QNames are used to create a mapping between URIs and namespace prefixes. The mapping makes it possible to abbreviate URIs, which provides a more convenient way to write XML documents.

Example

  <?xml version='1.0'?>
  <doc xmlns:x="http://example.com/ns/foo">
    <x:p/>
  </doc>

In the second line, the prefix "x" is declared to be associated with the URI "http://example.com/ns/foo". This prefix can then be used as an abbreviation for this namespace. As a result, the tag "x:p" is a valid QName because it uses "x" as the namespace reference and "p" as the local part. The tag "doc" is also a valid QName, but it consists only of a local part.

In Python

lxml.etree.QName.QName

See also

Favorite site

author Zer0 sitemap