Features
1. Prettify XML (XML Formatting)
2. Pretty XML: Minimize
Pretty XML is a XML formatter extension for Visual Studio Code and VSCodium. It formats XML documents just like Visual Studio on Windows.
Supported file extensions:
- xml
- xaml
- axml
- xsd
- xsl
- plist
- mobileconfig
- config
- csproj
- svg
- resx and all other XML type of files.
There is also Visual Studio for Mac version of this extension. Check it out at PrettyXML.VSMac
Suggestions, improvement PRs are welcome.
Right Click and Select Prettify XML or use shortcut
- Position each attribute on a separate line.
- First attribute on same line as start element start tag.
- All attributes indented aligning with first attribute.
- If no child for an element then close inline end tag.
- No empty lines.
- Supports
'and whitespace unicodes in attribute value for XAML parser compatibility.
- Lets you format entire valid XML document.
- Lets you format part of an XML document. XML can be partial and invalid. This is in beta, so feel free to submit pull request with improvements.
Before
After
Minimizes XML.
| Command | Platform | Shortcut |
|---|---|---|
| Prettify XML | Mac | Cmd+K L |
| Prettify XML | Windows, Linux | Control+K L |
| PrettyXML: Minimize | Mac | Cmd+K ` |
| PrettyXML: Minimize | Windows, Linux | Control+K ` |
Note
You can change these in Preferences → Keyboard Shortcuts if you want.
These will be for Prettify XML command.
| Setting Key | Default Value | Description |
|---|---|---|
| prettyxml.settings.indentSpaceLength | 4 | No. of spaces for indentation. |
| prettyxml.settings.useSingleQuotes | false | Use ' instead of " |
| prettyxml.settings.useSelfClosingTag | true | If no child nodes then self closing tag /> |
| prettyxml.settings.formatOnSave | false | Enable format on save |
| prettyxml.settings.allowSingleQuoteInAttributeValue | true | Allows ' in attribute values instead of ' |
| prettyxml.settings.addSpaceBeforeSelfClosingTag | true | Adds space before self closing tag |
| prettyxml.settings.wrapCommentTextWithSpaces | true | Wraps comment text with a single space |
| prettyxml.settings.allowWhiteSpaceUnicodesInAttributeValues | true | Allows white space unicodes in attribute values |
| prettyxml.settings.positionFirstAttributeOnSameLine | true | Position first attribute on same line. |
| prettyxml.settings.positionAllAttributesOnFirstLine | false | Position all attributes on first line |
| prettyxml.settings.preserveWhiteSpacesInComment | false | Preserves whitespaces in a comment. |
| prettyxml.settings.addSpaceBeforeEndOfXmlDeclaration | false | Add space before end of XML declaration. |
| prettyxml.settings.addXmlDeclarationIfMissing | true | Add XML declaration if missing. |
| prettyxml.settings.attributesInNewlineThreshold | 1 | Attributes count threshold to position attributes in newlines. |
| prettyxml.settings.enableLogs | false | Enables logs |
| prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine | Array<string> | Wild card exceptions for elements to ignore positionAllAttributesOnFirstLine |
| prettyxml.settings.addEmptyLineBetweenElements | false | Add empty line between elements if the child count is greater than 2 |
| prettyxml.settings.addEmptyEol | false | Add empty EOL to files if it does not exist. |
| prettyxml.settings.preserveNewLines | false | Preserve existing new lines between elements. |
| prettyxml.settings.preserveCommentPlacement | false | Preserve comment line placement. |
| prettyxml.settings.escapeInvisibleNonAsciiCharacters | false | Escape invisible non-ASCII characters as character references. |
The top of the settings pane. Each entry carries its default and, where it helps, a worked example. The table above is the complete list - search
prettyxmlin Settings to scroll through them all.
Example:
Value = 2
<Element Attribute1="Value1" Attribute2="Value2" /><Element Attribute1="Value1" Attribute2="Value2" /><Element Attribute1="Value1" Attribute2="Value2" Attribute3="Value3" /><Element Attribute1="Value1"
Attribute2="Value2"
Attribute3="Value3"/>List of element names to ignore Position All Attributes On First Line setting. Include element names or patterns here.
Example:
"prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine": ["Content*"]<View>
<Content X="X"
Y="Y" Z="Z">
<Label text="{i18>LabelText}" />
<Input id="Input1"
value="{service>description}" />
</Content>
</View><View>
<Content X="X"
Y="Y"
Z="Z">
<Label text="{i18>LabelText}" />
<Input id="Input1" value="{service>description}" />
</Content>
</View>If enabled, and child elements count is greater than 2 then adds empty line between elements.
Note
Please note it wont add empty element before first element and after last element.
<Root>
<Element1>Text1</Element1>
<Element2>Text2</Element2>
<Element3>Text3</Element3>
</Root><Root>
<Element1>Text1</Element1>
<Element2>Text2</Element2>
<Element3>Text3</Element3>
</Root>Adds XML declaration <?xml version="1.0" encoding="utf-8"?> if missing.
Default is true.
Preserves existing new lines between elements.
Example: Value = false
<Root>
<Element1>Text1</Element1>
<Element2>Text2</Element2>
<Element3>Text3</Element3>
<Element3>Text4</Element3>
</Root><Root>
<Element1>Text1</Element1>
<Element2>Text2</Element2>
<Element3>Text3</Element3>
<Element3>Text4</Element3>
</Root>Example: Value = true
<Root>
<Element1>Text1</Element1>
<Element2>Text2</Element2>
<Element3>Text3</Element3>
<Element3>Text4</Element3>
</Root><Root>
<Element1>Text1</Element1>
<Element2>Text2</Element2>
<Element3>Text3</Element3>
<Element3>Text4</Element3>
</Root>Preserve existing comment line placement. Default is Unchecked
Checked : Comments remains in their original lines. Unchecked : Comments may be repositioned into other lines according to formatting rules.
Example: Value = false
<Root>
<Element1>Text1</Element1> <!--A comment-->
<Element2>Text2</Element2><!--Another comment-->
<Element3>Text3</Element3>
</Root><Root>
<Element1>Text1</Element1>
<!--A comment-->
<Element2>Text2</Element2>
<!--Another comment-->
<Element3>Text3</Element3>
</Root>Example: Value = true
<Root>
<Element1>Text1</Element1> <!--A comment-->
<Element2>Text2</Element2> <!--Another comment-->
<Element3>Text3</Element3>
</Root><Root>
<Element1>Text1</Element1><!--A comment-->
<Element2>Text2</Element2><!--Another comment-->
<Element3>Text3</Element3>
</Root>Adds an empty line (trailing newline) at the end of formatted files if one does not exist.
Default is false (Unchecked).
- Checked (
true): Ensures the formatted document ends with a trailing newline (matching CRLF or LF based on the file). - Unchecked (
false): Preserves the original file's trailing line ending without forcing one if it did not exist.
Escapes the non-ASCII characters that draw nothing - non-breaking and zero-width spaces, joiners, bidi marks, the soft hyphen and the BOM - as numeric character references, so you can see what is actually in the file.
Default is false (Unchecked).
- Checked (
true): Invisible non-ASCII characters are written as&#x...;references. - Unchecked (
false): Invisible non-ASCII characters are written as literal characters.
Characters that draw something are left literal at either setting - ü, 日 and 😀 are never escaped.
Applies to element text and attribute values. CDATA sections and comments resolve no character references, so their contents are left untouched either way.
Tab, newline and carriage return are ASCII, and are decided by
prettyxml.settings.allowWhiteSpaceUnicodesInAttributeValuesinstead. The two settings cover different characters and neither overrides the other.
The examples below write the invisible characters as references on the input side so they can be read -   is a non-breaking space and ​ is a zero-width space.
Example: Value = false
<Invoice>
<Line note="10 km">Total price​: 12 €</Line>
<Customer>Müller</Customer>
</Invoice><Invoice>
<Line note="10 km">Total price: 12 €</Line>
<Customer>Müller</Customer>
</Invoice>The non-breaking and zero-width spaces are still there - they are just indistinguishable from an ordinary space and from nothing at all.
Example: Value = true
<Invoice>
<Line note="10 km">Total price​: 12 €</Line>
<Customer>Müller</Customer>
</Invoice><Invoice>
<Line note="10 km">Total price​: 12 €</Line>
<Customer>Müller</Customer>
</Invoice>The € and the ü are visible characters, so they stay literal in both.
- DotNet 10 installed on your machine and should be accessible through terminal.
- Install Muhammad-Sammy C# or Microsoft C# extension.
- Visual Studio Code/VSCodium 1.99.1 or higher.
Visual Studio Code - Visual Studio MarketPlace
For VSCodium - open-vsx.org
- Limited DTD support.
- Formats valid XML files only. Syntax errors are displayed.
Issues can be reported at issues section






