XML
Available in AxoSyslog 4.9 and later.
The parse_xml()
FilterX function parses raw XMLs into dictionaries. This is a new implementation, so the limitations and options of the legacy xml-parser()
do not apply.
There is no standardized way of converting XML into a dict. AxoSyslog creates the most compact dict possible. This means certain nodes will have different types and structures depending on the input XML element. Note the following points:
-
Empty XML elements become empty strings.
XML: <foo></foo> JSON: {"foo": ""}
-
Attributions are stored in
@attr
key-value pairs, similarly to other converters (like python xmltodict).XML: <foo bar="123" baz="bad"/> JSON: {"foo": {"@bar": "123", "@baz": "bad"}}
-
If an XML element has both attributes and a value, we need to store them in a dict, and the value needs a key. We store the text value under the
#text
key.XML: <foo bar="123">baz</foo> JSON: {"foo": {"@bar": "123", "#text": "baz"}}
-
An XML element can have both a value and inner elements. We use the
#text
key here, too.XML: <foo>bar<baz>123</baz></foo> JSON: {"foo": {"#text": "bar", "baz": "123"}}
-
An XML element can have multiple values separated by inner elements. In that case we concatenate the values.
XML: <foo>bar<a></a>baz</foo> JSON: {"foo": {"#text": "barbaz", "a": ""}}
Usage
my_structured_data = parse_xml(raw_xml);