XML
Synopsis
Parses XML-formatted strings into structured maps.
Schema
xml:
- field: <ident>
- target_field: <ident>
- description: <text>
- if: <script>
- add_to_root: <boolean>
- ignore_failure: <boolean>
- ignore_missing: <boolean>
- on_failure: <processor[]>
- on_success: <processor[]>
- tag: <string>
Configuration
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 |
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 |
Details
The processor converts XML documents into nested map structures, handling complex scenarios like nested elements, attributes, and mixed content.
Attributes are stored in a special _attributes
map within the element. Text content is stored under:
_text
for elements with attributes_content
for elements without attributes
For mixed content, such as nested structures, both the layout and the text is preserved. Repeated elements are automatically converted to arrays.
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: |
|
Complex Nested
Parsing complex XML with nested elements and attributes... |
|
preserves the layout and attributes: |
|