gws.plugin.xml_helper

Helper for custom XML namespaces.

The helper registers custom XML namespaces, which can then be used in generated XML documents. The namespaces are configured in the namespaces list and registered globally in gws.lib.xmlx.namespace when the helper is configured. Other code can add namespaces at run time with add_namespace.

By default, a custom namespace is declared to extend the GML3 schema.

Example:

helpers+ {
    type "xml"
    namespaces+ {
        xmlns "demo"
        uri "https://example.com/namespace/demo"
        schemaLocation "https://example.com/namespace/demo.xsd"
    }
}

Example:

helper = root.app.helper('xml')
ns = helper.add_namespace(gws.Config(xmlns='demo', uri='https://example.com/namespace/demo'))

Source code: gws.plugin.xml_helper

Package Contents

class gws.plugin.xml_helper.Config(*args, **kwargs)

Bases: gws.Config

Custom XML namespaces for generated XML documents.

namespaces: list[NamespaceConfig]

Custom namespaces to register.

class gws.plugin.xml_helper.NamespaceConfig(*args, **kwargs)

Bases: gws.Config

Custom XML namespace for generated XML documents.

extendsGml: bool = True

Namespace schema extends the GML3 schema.

schemaLocation: gws.Url | None

URL of the namespace XML schema.

uri: gws.Url

Namespace URI.

version: str = ''

Ignored. (deprecated in 8.5)

xmlns: str

Default prefix for this namespace.

class gws.plugin.xml_helper.Object

Bases: gws.Node

XML helper, which registers custom namespaces.

add_namespace(cfg: NamespaceConfig) → gws.XmlNamespace

Create a custom namespace and register it globally.

Parameters:

cfg – Namespace configuration.

Returns:

The registered namespace.

Raises:

gws.ConfigurationError – If the prefix or the URI conflicts with an already registered namespace.

configure()

Configuration hook.

Called when the node is initialized. Raising an exception here aborts the creation of the node.