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(namespaces: dict[str, gws.XmlNamespace], with_schema_locations: bool = False) dict ¶
Returns an xmlns declaration block as dictionary of attributes.
- Parameters:
namespaces – Mapping from prefixes to namespaces.
with_schema_locations – Add the “schemaLocation” attribute.
- Returns:
A dict of attributes.
- gws.lib.xmlx.namespace.extract(name: str) tuple[gws.XmlNamespace | None, str] ¶
Extract a Namespace object from a qualified name.
- Parameters:
name – XML name.
- Returns:
A tuple
(XmlNamespace, proper name)
- gws.lib.xmlx.namespace.find_by_uri(uri: str) gws.XmlNamespace | None ¶
Locate the Namespace by an Uri.
- gws.lib.xmlx.namespace.find_by_xmlns(xmlns: str) gws.XmlNamespace | None ¶
Locate the Namespace by an xmlns prefix.
- gws.lib.xmlx.namespace.from_args(**kwargs) gws.XmlNamespace ¶
Create a Namespace from keyword arguments.
- gws.lib.xmlx.namespace.get(uid: str) gws.XmlNamespace | None ¶
Locate the Namespace by a uid.
- gws.lib.xmlx.namespace.qualify_name(name: str, ns: gws.XmlNamespace | None = None, replace: bool = False) str ¶
Qualify an XML name.
- 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)¶
Add a Namespace to an internal registry.
- gws.lib.xmlx.namespace.require(uid: str) gws.XmlNamespace ¶
Locate the Namespace by a uid.
- gws.lib.xmlx.namespace.split_name(name: str) tuple[str, str, str] ¶
Parse an XML name in a xmlns: or Clark notation.
- Parameters:
name – XML name.
- Returns:
A tuple
(xmlns-prefix, uri, proper name)
.
- gws.lib.xmlx.namespace.unqualify_default(name: str, default_namespace: 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_namespace – A namespace.
- Returns:
The name.
- gws.lib.xmlx.namespace.unqualify_name(name: str) str ¶
Returns an unqualified XML name.
- gws.lib.xmlx.namespace.XMLNS = 'xmlns'¶