Skip to content

Commit

Permalink
Add more config properties to xml input filter
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Mar 15, 2024
1 parent 4d514e0 commit 6e545aa
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ogc/na/input_filters/xml.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""
XML Input filter for ingest_json.
Processes XML files with [xmltodict](https://pypi.org/project/xmltodict/).
Processes XML files with [xmltodict](https://pypi.org/project/xmltodict/). Attributes are prefixed with `_` instead
of `@` by default.
Configuration values:
* `process-namespaces` (default: `False`): Whether to process and expand namespaces (see xmltodict documentation)
* `namespaces` (default: `None`): Namespace to prefix mappings dict in `url: prefix` format.
* `attr-prefix` (default: `_`): Prefix that will be used for attributes (in order to avoid potential clashes with
element names).
* `namespace-separator` (default `:`): String that will be used to separate the namespace prefix and the local name
when processing namespaces.
* `text-property` (default: `_`): property name that will be used to put the element's text content into
"""
from __future__ import annotations

Expand All @@ -19,6 +25,9 @@
DEFAULT_CONF = {
'process-namespaces': False,
'namespaces': None,
'attr-prefix': '_',
'namespace-separator': ':',
'text-property': '_',
}


Expand All @@ -34,6 +43,10 @@ def apply_filter(content: bytes, conf: dict[str, Any] | None) -> tuple[dict[str,
textio = StringIO(content.decode('utf-8'))
result = xmltodict.parse(textio.read(),
process_namespaces=conf['process-namespaces'],
namespaces=conf['namespaces'])
namespaces=conf['namespaces'],
attr_prefix=conf['attr-prefix'],
namespace_separator=conf['namespace-separator'],
cdata_key=conf['text-property'],
)

return result, metadata

0 comments on commit 6e545aa

Please sign in to comment.