Format XML to a Max Line Length

Format XML in @rawstring field using the xml:prettyPrint() function with custom formatting parameters set

Query

logscale
formattedXml := xml:prettyPrint(field=payload, step=4, width=100)

Introduction

The xml:prettyPrint() function can be used to format an XML field for improved readability. When used without parameters, xml:prettyPrint() assumes, that the XML is in the @rawstring field.

In this example, the xml:prettyPrint() function is used with parameters to format the XML data in the payload field to a max line length of 100 and indent by 4 spaces.

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0>Augment Data] result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    formattedXml := xml:prettyPrint(field=payload, step=4, width=100)

    Uses the field parameter to specify the payload field as the source of XML data, the step parameter set to 4, and the width parameter set to 100 to format the XML data in the payload field to a max line length of 100 and indent by 4 spaces.

    The results are assigned to a new field named formattedXml.

  3. Event Result set.

Summary and Results

The query is used to make XML data more readable in the results by defining a max line length of 100 and indent by 4 spaces.