vscode-xml provides a number of notable features, with demos below.
To format an XML document, you can use the formatting shortcut Ctrl + Shift + K
.
For more information on formatting capabilities, see Formatting.
XML tag folding is supported:
To collapse and expand a tag, press the arrow.
For more information on folding capabilities, see Folding.
XML tag auto-close
is supported:
Using /
in an opening tag will auto close the tag.
Linked editing is supported, allowing for simultaneous changes an opening and closing tag pair.
To enable this feature, the setting editor.linkedEditing
must be set to true
in your settings.json
.
For quick navigation, you can use Ctrl + Click
on a closing tag to jump to the corresponding opening tag.
The same applies to jumping from an opening tag to the respective closing tag.
To rename a single tag and its corresponding opening/closing, highlight the tag and press F2
or use the dropdown to select Rename Symbol
.
When placing the cursor on an XML tag, the corresponding opening/closing tag will be highlighted.
The OUTLINE
dropdown under EXPLORER
details the XML tags in the document and their children. The Breadcrumbs
bar also shows the hierarchy of the tag that the cursor is on. Both features permit jumping to the tag(s) displayed.
When starting a new XML document, Ctrl
+ Space
lists different snippet options to set up the document.
There are also a number of keywords that will be recognized as snippets and autocompleted. For example, typing schema
will list schema related snippet options.
If an XML file is not associated to a bound grammar file, you can utilize XML completion which uses existing XML tag elements.
For an XML tag attribute, there is autocompletion support for the attribute value. For example, for path completion, type .
or /
.
When an XML file is associated with an XSD file, there is support for completion based on the tags, attribute names and values defined in the XML Schema/XSD file.
When XML file is associated with a DTD file, completion based on tags, attributes name and value defined in the DTD file are supported.
If an XML file is associated with an XSD file, there is support for jumping from the XML tag to the schema definition.
When XML file is associated with an XSD file, hover documentation based on tags, attributes name and value defined in the XML Schema/XSD file are supported.
When XML file is associated with a DTD file, hover documentation based on tags, attributes name and value defined in the DTD file are supported.
LemMinX will show syntax errors in your XML documentation, and will provide quick fixes to resolve these errors.
There is also validation based on grammar when an XSD or DTD file is associated with the XML document.
See XML Validation for more details.
For any XML document, should you need to bind a grammar or schema with the file, you can do so by either using an existing grammar file, or by generating one using the built-in schema generator.
See Binding with Existing Grammar for info on binding to an existing schema.
See Binding with New Grammar for info on grammar generation.
You can use Alt + Shift + Right Arrow
to expand your selection range according to the structure of the XML document.
For instance, if you expand the selection range in an element with text content, it will first select all the text content, then the element.
This also works for other portions of an XML document, such as attributes and the DTD subset.
CodeLens is supported for .xml
files for a number of different features.
If the current XML document is not bound to an existing grammar/schema, a CodeLens will appear above the root element, which will trigger the XML Binding Wizard.
For more information on CodeLens capabilities, see CodeLens.
You can implement your own feature with a Java extension.