'Pretty prints' an XML field. The function formats an XML field for improved readability. This can be an expensive operation.
It is recommended to apply xml:prettyPrint()
after filtering your data at the end of the query. This prevents unnecessary formatting of data that will be discarded.
Default behaviour is as follows:
If the field does not contain valid XML, the unmodified input value is stored in the output field.
If no field is specified, the @rawstring field will be formatted.
Parameter | Type | Required | Default Value | Description |
---|---|---|---|---|
as | string | optional[a] | The name of the field to store the output in. | |
field [b] | string | required | @rawstring | The name of the field to format. |
step | integer | optional[a] | 2 | The indentation in number of characters. |
strict | boolean | optional[a] | false | If set to true only valid XML input produce a value in the output field. By default invalid XML is copied to the output field unmodified. |
width | integer | optional[a] | 80 | The width (in number of characters) to fit the output input. |
[a] Optional parameters use their default value unless explicitly set. |
Hide omitted argument names for this function
Omitted Argument NamesThe argument name for
field
can be omitted; the following forms of this function are equivalent:logscale Syntaxxml:prettyPrint("value")
and:
logscale Syntaxxml:prettyPrint(field="value")
These examples show basic structure only.
xml:prettyPrint()
Examples
Click
next to an example below to get the full details.Format Only Valid XML
Format only XML data that is considered valid using the xml:prettyPrint()
function
Query
formattedXml := xml:prettyPrint(field=message, strict=true)
Introduction
In this example, the xml:prettyPrint()
function is used to format the message field
as XML with the
strict
parameter set to true
to only process valid
XML.
Step-by-Step
Starting with the source repository events.
- logscale
formattedXml := xml:prettyPrint(field=message, strict=true)
Uses the
field
parameter to specify the message field as the source of XML data and thestrict
parameter set totrue
to only process valid XML.Formats the valid XML data for improved readability and assigns the results to a new field named formattedXml.
Note that if the XML in the message field is invalid, the formattedXml field will not be created for that event.
Event Result set.
Summary and Results
The query is used to make valid XML data more readable in the results.
Note that without
strict
parameter
set to true
, the
xml:prettyPrint()
function attempts to format even
invalid XML, which might lead to unexpected results.
Format XML
Format XML in @rawstring field using the xml:prettyPrint()
function
Query
#type=SOAP
| account=123
| xml:prettyPrint()
Introduction
In this example, the xml:prettyPrint()
function is used to format the @rawstring
field.
Step-by-Step
Starting with the source repository events.
- logscale
#type=SOAP
Filters for events with the
XML
type. - logscale
| account=123
Filters for events related to account 123.
It is recommended to filter the event set as much as possible before using the
xml:prettyPrint()
function to prevent unnecessary formatting of discarded data. - logscale
| xml:prettyPrint()
Formats the
XML
content for improved readability. Without a specified field, it formats the @rawstring field.Note that if input is not valid XML, it returns unmodified values. To prevent this, you can set a
strict
parameter. For an example of usage, see Format Only Valid XML. Event Result set.
Summary and Results
The query is used to make XML data more readable in the results. Formatting XML in the @rawstring field after filtering the data is very important as it is a resource-intensive operation.
Format XML to a Max Line Length
Format XML in @rawstring field using the xml:prettyPrint()
function with custom formatting parameters set
Query
formattedXml := xml:prettyPrint(field=payload, step=4, width=100)
Introduction
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
Starting with the source repository events.
- 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, thestep
parameter set to4
, and thewidth
parameter set to100
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.
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.