@prettier/plugin-xml is a prettier plugin for XML. prettier is an opinionated code formatter that supports multiple languages and integrates with most editors. The idea is to eliminate discussions of style in code review and allow developers to get back to thinking about code design instead.
Getting started
To run prettier with the XML plugin, you're going to need node.
If you're using the npm CLI, then add the plugin by:
In XML, by default, all whitespace inside elements has semantic meaning. For prettier to maintain its contract of not changing the semantic meaning of your program, this means the default for xmlWhitespaceSensitivity is "strict". When running in this mode, prettier's ability to rearrange your markup is somewhat limited, as it has to maintain the exact amount of whitespace that you input within elements.
If you're sure that the XML files that you're formatting do not require whitespace sensitivity, you can use the "ignore" option, as this will produce a standardized amount of whitespace. This will fix any indentation issues, and collapse excess blank lines (max of 1 blank line). For most folks most of the time, this is probably the option that you want.
You can also use the "preserve" option, if you want to preserve the whitespace of text nodes within XML elements and attributes. See #478 for more detail.
Ignore ranges
You can use two special comments to get prettier to ignore formatting a specific piece of the document, as in the following example: