XML

Available in AxoSyslog 4.13 and later.

Formats a dictionary into XML. To format data as Windows Event Log XML, see Windows Event Logs XML.

Usage: format_xml({"key1":{"nestedkey":"value"}})

The output XML for the previous example will be: <key><nestedkey>value</nestedkey></key>

Note the following points:

  1. Store attributions in @attr key-value pairs.

    JSON: {"foo": {"@bar": "123", "@baz": "bad"}}
    XML:  <foo bar="123" baz="bad"/>
    
  2. If an XML element has both attributes and a value, store text value under the #text key.

    JSON: {"foo": {"@bar": "123", "#text": "baz"}}
    XML:  <foo bar="123">baz</foo>
    
  3. An XML element can have both a value and inner elements. We use the #text key here, too.

    JSON: {"foo": {"#text": "bar", "baz": "123"}}
    XML:  <foo>bar<baz>123</baz></foo>
    
  4. JSON lists become values of separate tags:

    JSON: {"a":{"b":["c","d"]}}
    XML:  <a><b>c</b><b>d</b></a>
    

    You can add attributions for specific elements of such lists:

    JSON: {"a":{"b":["c",{"@attr":"attr_val","#text":"e"}]}}
    XML:  <a><b>c</b><b attr='attr_val'>e</b></a>
    
  5. A top-level JSON lists becomes a multi-root XML:

    JSON: {"a":["b","c"]}
    XML:  <a>b</a><a>c</a>
    
  6. Numeric values become text:

    JSON: {"a":100}
    XML:  <a>100</a>
    
  7. Empty elements are represented as short-format XML tags:

    JSON: {"a":""}
    XML:  <a/>