XML
Synopsis
Parses XML-formatted strings into structured maps.
Schema
- xml:
field: <ident>
target_field: <ident>
description: <text>
if: <script>
add_to_root: <boolean>
attribute_prefix: <string>
compact: <boolean>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
Configuration
The following fields are used to define the processor:
| Field | Required | Default | Description |
|---|---|---|---|
field | Y | Field containing the XML string to parse | |
target_field | N | Field to store the parsed XML structure. If omitted and add_to_root is false, an error is raised | |
description | N | - | Explanatory note |
if | N | - | Conditional expression to determine if processing should occur |
add_to_root | N | false | If true, adds parsed XML elements directly to the log entry root |
attribute_prefix | N | _ | Prefix applied to attribute keys. Attributes become ordinary sibling keys of the element, distinguished only by this prefix |
compact | N | false | Collapse the wrapper maps where it is unambiguous. See Compact Mode below |
ignore_failure | N | false | Skip processing if an error occurs |
ignore_missing | N | false | Skip processing if the source field is missing |
on_failure | N | - | Processors to run if processing fails |
on_success | N | - | Processors to run after successful processing |
tag | N | - | Identifier for logging purposes |
disabled | N | false | When true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration |
Details
The processor converts XML documents into nested map structures, handling complex scenarios like nested elements, attributes, and mixed content.
Every element becomes a map, and the parser uses exactly two conventions:
- Element text goes under the
__textkey — two underscores. This applies to every element that has text, whether or not it also has attributes, so even a leaf element is a map:<name>John</name>parses to{"name": {"__text": "John"}}, not to the bare string. - Attributes become ordinary sibling keys prefixed with
attribute_prefix(_by default).<user id="123">gives the key_id. They are not collected into a separate map.
Repeated elements are converted to arrays. Mixed content preserves both: <message>Hello <b>World</b>!</message> parses to {"message": {"__text": "Hello !", "b": {"__text": "World"}}} — the element's own text is joined with a space and kept alongside the child.
An empty element that carries attributes still gets __text: "", so the key is always present where text was possible.
Invalid XML will cause processing to fail unless ignore_failure is set to true.
Examples
Basic
Parsing a simple XML structure... | |
creates a structured map: | |
Attributes
Parsing XML with element attributes... | |
handles each separately: | |
Repeated Elements
Parsing XML with repeated elements... | |
converts repeated elements to arrays: | |
Adding to Root
Adding parsed XML directly to log entry root... | |
adds the elements directly: | |
Compact Mode
Windows | |
which leaves an array you have to walk by index: | |
With | |
giving named fields you can reference directly: | |
The collapse is deliberately narrow. It applies only where the shape is unambiguous:
- An element with
__textand exactly one attribute and nothing else becomes{<attribute value>: <text>}. - An element with
__textand nothing else becomes the bare text string.
Anything else — two attributes, a child element alongside the text — is left as it is. An EventData block mixing <Data Name="..."> with <Data Type="..."> elements does not collapse, because the elements do not share one attribute name.
Complex Nested
Parsing complex XML with nested elements and attributes... | |
preserves the layout and attributes: | |