I would like to write an XML Schema in Visual Studio Code and then some XML that is valid against that schema but surprisingly there does not seem to be a facility to do this either built-in or via an extension. Similar questions have been asked in the past (here and here) but I wanted to renew this question and also ask if no-one is aware of an existing extension, is this something one can request of the vscode github team themselves and if so, how?
-
What version are you using? 2015 Enterprise has support for XML/XSD design and development.– spodgerCommented Dec 15, 2017 at 14:42
-
I'm using Visual Studio Code, not the grown up Enterprise.– Dan MaharryCommented Dec 15, 2017 at 16:16
-
Have you tried looking on Nuget?– spodgerCommented Dec 15, 2017 at 18:55
-
@spodger Yes, but as I said there don't appear to be any– Dan MaharryCommented Dec 27, 2017 at 13:09
5 Answers
The XML extension, by Red Hat, is now available in the Marketplace. It supports, among other things, XSD and DTD validation, autocompletion from XSD, documentation on hover, tag autoclose, formatting...
It's based on LemMinX, a Java-based language server.
As of vscode-xml 0.15.0, Java is no longer required to run it (a native binary will be downloaded on install).
-
3This is a good extension but also requires java to be on the path or in VSC preferences, e.g.
"java.home": "C:/Program Files/Java/jdk1.8.0_191"
(N.B. no /bin)– SlateCommented Nov 7, 2018 at 16:55 -
An awesome extension, best of all it allows XML to XSD association in a variety of ways, and provides a simple example package. Got it working in 5 minutes, which is more than I can say for the other products I have used in this space over the years.– MattGCommented Nov 20, 2018 at 21:57
-
Most of the frameworks use urn paths for xsd files, is there any way to map the files in vs code? Commented Jun 25, 2019 at 12:46
-
1@VivekKumar I suppose you wish to use XML catalogs. If it that you can write your own XML catalog and register it with xml.catalogs preferences github.com/redhat-developer/vscode-xml/wiki/…– AngeloCommented Jul 1, 2019 at 14:55
-
@kjhf
"xml.java.home": "C:\\Program Files\\Java\\jdk1.8.0_161"
– JustWeCommented Jul 17, 2019 at 8:38
I just found Xml Complete by rogalmic that doesn't need Java to be installed.
Features:
- Basic linter (XML + partial XSD validation)
- Fast autocomplete based on XSD (utilizes comments from XSD)
- Formatting XML (selected range or full document)
- Auto-closing and auto-rename for currently edited tag (works only for single tag in given line)
All you need to do is to specify the xsd in the root of your xml.
Here's an example:
<?xml version="1.0"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:schemaLocation="MyPathToMyXsd/MySchema.xsd">
<!-- Xml content -->
</Root>
You can install XML Language Support extension which support Structural XML validation and XML Schema Definition (XSD) validation, by launching VS Code and then Quick Open (Ctrl+P), paste the following command
ext install IBM.XMLLanguageSupport
, and press enter. After installation press Reload button to activate . You may need to install Language Support for Java(TM) if you have not before by using the following command in VS Code extensions
ext install redhat.java
There actually is a XML/XSD editor and validator for VSCode here.
Alhough it requires java (docs state java 8) to be installed.
Not built-in, but there are a few extensions in the marketplace:
-
12None of which actually do the schema validation thing or support schema writing with intellisense. Commented Dec 27, 2017 at 13:09