The built-in XML text formatter can adjust whitespace between elements and attributes to make code more readable.
The Text Formatting topic talks about text formatters in general and how to register them as a "feature" language service.
The Xml
Registering with a Syntax Language
Any object that implements IText
The Xml
This code creates a custom text formatter (defined in a make-believe CustomXmlTextFormatter
class) and registers it with the syntax language that is already declared in the language
variable:
Note
The SyntaxActiproSoftware.Text
namespace is imported. See the Service Locator Architecture topic for details on registering and retrieving various service object instances, both via extension methods and generically, as there are some additional requirements for using the extension methods.
Disabling the Functionality
Since this feature is installed as a "feature" service on the language and is installed on Xml
Attribute Spacing Mode
The Xml
Mode | Formatter Behavior |
---|---|
Preserve |
The formatter will not make changes to the whitespace around attributes. This is the default mode. |
NormalizeWhitespace |
The formatter will adjust any whitespace around attributes to be exactly one space. |
SeparateLines |
The formatter will adjust any whitespace such that each attribute is on a separate line. |
Element Spacing Mode
The Xml
Mode | Formatter Behavior |
---|---|
Preserve |
The formatter will not make changes to the whitespace in element content. This is the default mode. |
NormalizeEmptyLines |
The formatter will adjust any whitespace around element content so that there is no more than a single empty line between the content and the containing element. |
RemoveEmptyLines |
The formatter will remove extra whitespace around element content. The actual result depends on the type of content, which can be text-only, one or more elements, or mixed content. |
Tag Wrap Length
The Xml
Setting the value to 0
(zero) will disable the feature, which is the default value. When enabling this wrap feature, a common setting is 120
.