Coverage for gws-app/gws/plugin/xml_helper/__init__.py: 0%
33 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1"""XML helper."""
3import gws
4import gws.lib.xmlx
6gws.ext.new.helper('xml')
9DEFAULT_NS_URI = '/_/owsXml/namespace/{}'
10DEFAULT_NS_SCHEMA_LOCATION = '/_/owsXml/namespace/{}.xsd'
13class NamespaceConfig(gws.Config):
14 """XML Namespace configuration. (added in 8.1)"""
16 xmlns: str
17 """Default prefix for this Namespace."""
18 uri: gws.Url
19 """Namespace uri."""
20 schemaLocation: gws.Url
21 """Namespace schema location."""
22 version: str = ''
23 """Namespace version."""
24 extendsGml: bool = True
25 """Namespace schema extends the GML3 schema."""
28class Config(gws.Config):
29 """XML helper. (added in 8.1)"""
31 namespaces: list[NamespaceConfig]
34class Object(gws.Node):
35 namespaces: list[gws.XmlNamespace]
37 def configure(self):
38 self.namespaces = []
39 for c in self.cfg('namespaces', default=[]):
40 self.add_namespace(c)
42 def add_namespace(self, cfg: NamespaceConfig) -> gws.XmlNamespace:
43 """Add a custom namespace for XML generation."""
45 xmlns = cfg.get('xmlns')
46 ns = gws.XmlNamespace(
47 xmlns=xmlns,
48 uid=cfg.get('uid') or 'gws.base.helper.xml.' + xmlns,
49 uri=cfg.get('uri'),
50 schemaLocation=cfg.get('schemaLocation'),
51 version=cfg.get('version') or '',
52 extendsGml=cfg.get('extendsGml') or True,
53 )
55 gws.lib.xmlx.namespace.register(ns)
56 self.namespaces.append(ns)
58 return ns
60 def activate(self):
61 for ns in self.namespaces:
62 gws.lib.xmlx.namespace.register(ns)