解码 XML
decode_xml
处理器用于解码存储在 field
键下的 XML 数据。它将结果输出到 target_field
。
此示例演示如何解码 message
字段中包含的 XML 字符串,并将结果字段写入文档的根目录。任何已存在的字段都将被覆盖。
processors:
- decode_xml:
field: message
target_field: ""
overwrite_keys: true
默认情况下,发生的任何解码错误都将停止处理链,并且错误将添加到 error.message
字段中。要忽略所有错误并继续处理下一个处理器,可以将 ignore_failure: true
。要专门忽略由 field
不存在引起的错误,可以将 ignore_missing: true
。
processors:
- decode_xml:
field: example
target_field: xml
ignore_missing: true
ignore_failure: true
默认情况下,所有从 XML 转换的键名都将转换为小写。如果需要禁用此行为,可以使用以下示例
processors:
- decode_xml:
field: message
target_field: xml
to_lower: false
XML 输入示例
<catalog>
<book seq="1">
<author>William H. Gaddis</author>
<title>The Recognitions</title>
<review>One of the great seminal American novels of the 20th century.</review>
</book>
</catalog>
将产生以下输出
{
"xml": {
"catalog": {
"book": {
"author": "William H. Gaddis",
"review": "One of the great seminal American novels of the 20th century.",
"seq": "1",
"title": "The Recognitions"
}
}
}
}
支持的配置选项如下
field
- (必需) 包含 XML 的源字段。默认为
message
。 target_field
- (可选) 解码后的 XML 将写入的字段。默认情况下,解码后的 XML 对象会替换从中读取的字段。要将解码后的 XML 字段合并到事件的根目录,请将
target_field
指定为空字符串 (target_field: ""
)。请注意,null
值 (target_field:
) 被视为未设置该字段。 overwrite_keys
- (可选) 一个布尔值,指定事件中已存在的键是否被解码后的 XML 对象中的键覆盖。默认值为
true
。 to_lower
- (可选) 将所有键转换为小写。接受
true
或false
。默认值为true
。 document_id
- (可选) 用于作文档 ID 的 XML 键。如果配置了此项,该字段将从原始 XML 文档中移除,并存储在
@metadata._id
中。 ignore_missing
- (可选) 如果为
true
,当指定的字段不存在时,处理器将不会返回错误。默认为false
。 ignore_failure
- (可选) 忽略处理器产生的所有错误。默认为
false
。
请参阅 条件 了解支持的条件列表。