Page Summary
-
The Format class is used for outputting an XML document with customizable formatting options.
-
You can format an entire XML Document or a specific Element node into a string.
-
Formatting options can be set for encoding, indent strings, line separators, and whether to omit the XML declaration or encoding.
-
Methods like
setEncoding(),setIndent(),setLineSeparator(),setOmitDeclaration(), andsetOmitEncoding()allow for chaining to configure the format.
A formatter for outputting an XML document, with three pre-defined formats that can be further customized.
// Log an XML document with specified formatting options. const xml = '<root><a><b>Text!</b><b>More text!</b></a></root>'; const document = XmlService.parse(xml); const output = XmlService.getCompactFormat() .setLineSeparator('\n') .setEncoding('UTF-8') .setIndent(' ') .format(document); Logger.log(output);
Methods
| Method | Return type | Brief description |
|---|---|---|
format(document) | String | Outputs the given Document as a formatted string. |
format(element) | String | Outputs the given Element node as a formatted string. |
set | Format | Sets the character encoding that the formatter should use. |
set | Format | Sets the string used to indent child nodes relative to their parents. |
set | Format | Sets the string to insert whenever the formatter would normally insert a line break. |
set | |