gws.lib.xmlx.namespace

XML namespace manager.

Maintains a registry of XML namespaces (well-known and custom).

Source code: gws.lib.xmlx.namespace

Module Contents

gws.lib.xmlx.namespace.clarkify_name(name: str) str

Returns an XML name in the Clark notation.

Parameters:

name – A qualified XML name.

Returns:

The XML name in Clark notation.

gws.lib.xmlx.namespace.declarations(default_ns: gws.XmlNamespace | None = None, for_element: gws.XmlElement = None, extra_ns: list[gws.XmlNamespace] | None = None, with_schema_locations: bool = False) dict

Returns an xmlns declaration block as dictionary of attributes.

Parameters:
  • default_ns – Default namespace.

  • for_element – If given, collect namespaces from this element and its descendants.

  • extra_ns – Extra namespaces to create declarations for.

  • with_schema_locations – Add the “schema location” attribute.

Returns:

A dict of attributes.

gws.lib.xmlx.namespace.find_by_uri(uri: str) gws.XmlNamespace | None

Locate the Namespace by an Uri.

If the Uri ends with a version number, and there is no namespace for this specific Uri, try to locate a non-versioned Uri. That is, http://www.opengis.net/gml/9999 will look up for http://www.opengis.net/gml.

Parameters:

uri – An Uri like http://www.opengis.net/gml.

Returns:

A Namespace.

gws.lib.xmlx.namespace.find_by_xmlns(xmlns: str) gws.XmlNamespace | None

Locate the Namespace by a name.

Parameters:

xmlns – A name like gml.

Returns:

A Namespace.

gws.lib.xmlx.namespace.get(s: str) gws.XmlNamespace | None

Locate the Namespace by a name.

Parameters:

s – A uid like gml3, name like gml or an Uri like http://www.opengis.net/gml.

Returns:

A Namespace.

gws.lib.xmlx.namespace.parse_name(name: str) tuple[gws.XmlNamespace | None, str]

Parses an XML name.

Parameters:

name – XML name.

Returns:

A tuple (XmlNamespace, proper name)

gws.lib.xmlx.namespace.qualify_name(name: str, ns: gws.XmlNamespace, replace: bool = False) str

Qualifies an XML name.

If the name contains a namespace, return as is, otherwise, prepend the namespace.

Parameters:
  • name – An XML name.

  • ns – A namespace.

  • replace – If true, replace the existing namespace.

Returns:

A qualified name.

gws.lib.xmlx.namespace.register(ns: gws.XmlNamespace)

Register a Namespace.

Parameters:

ns – Namespace

gws.lib.xmlx.namespace.split_name(name: str) tuple[str, str, str]

Parses an XML name.

Parameters:

name – XML name.

Returns:

A tuple (xmlns, uri, proper name).

gws.lib.xmlx.namespace.unqualify_default(name: str, default_ns: gws.XmlNamespace) str

Removes the default namespace prefix.

If the name contains the default namespace, remove it, otherwise return the name as is.

Parameters:
  • name – An XML name.

  • default_ns – A namespace.

Returns:

The name.

gws.lib.xmlx.namespace.unqualify_name(name: str) str

Returns an unqualified XML name.