14

I was a Mac user with BBEdit & Co. Now I'm on Windows with VS Code. I'm looking for an easy solution to validate XML with VS Code. Is there an extension for this?

Thanks!

SamB
  • 9,039
  • 5
  • 49
  • 56
Haeme Ulrich
  • 153
  • 1
  • 2
  • 6

3 Answers3

12

I just wanted to know if my xml syntax was valid, and I didn't want to have to install and setup Java.

XML Tools from Qub worked great for me, I highly recommend it:
https://marketplace.visualstudio.com/items?itemName=qub.qub-xml-vscode

If you need to validate xml against a schema, some of the other more popular extensions might be better

Devin Rhode
  • 23,026
  • 8
  • 58
  • 72
  • 3
    How do you get it to actually tell you if your xml is valid? I don't see that option in the command palette? – SuperCow Feb 07 '20 at 22:43
  • try making it obviously invalid by deleting a `<` – Devin Rhode Feb 08 '20 at 13:11
  • @SuperCow There is an `XML DOCUMNET ` in the left functional area which below the `OUTLINE` . If the xml file is invalid, it will show invalidDocument – roamer Dec 28 '20 at 02:12
  • @roamer I see the outline in the bottom left of vscode below the workspace, but no `xml document`. Do I need to put a definition of xmltools in `settings`? – Timo Jun 22 '21 at 19:07
  • 1
    If I make the xml invalid by removing a bracket: no remark by vscode. I can format it with the tool and I have `evaluate xpath` when pressing `f1` – Timo Jun 22 '21 at 19:08
  • 1
    @Timo Firstly, you need to install XML Tools plugin, xml tree view is default enable. Secondly, open a XXX.xml file with VS Code. Finally, you will see the `XML DOCUMNET ` – roamer Dec 08 '21 at 07:00
  • No entry in any menu to validate XML against a XSD schema. – Aubin Apr 14 '23 at 11:22
9

For validation against a schema there is XML extension by Red Hat https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml this no longer requires Java since v0.15.0.

It supports a few ways of associating an *.xml with an *.xsd or *.dtd see the docs at https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md#validation-with-xsd-grammar

Most methods involve modifying the files or creating a catalog file but you can also associate files using settings.json.

XSD
"xml.fileAssociations": [
   {
       "pattern": "foo.xml",
       "systemId": "foo.xsd"
   }
]
DTD
"xml.fileAssociations": [
  {
      "pattern": "foo.xml",
      "systemId": "foo.dtd"
  }
]

File paths support wildcards and VS Code variables ${workspaceFolder}, ${fileDirname}, ${fileBasenameNoExtension}

Aquila Sands
  • 1,471
  • 1
  • 20
  • 28
7

There is "XML" extension (known as "XML Language Support by Red Hat") that does not require Java.

Old answer:

For validating XML Schemas in VS Code there is a package called XML Language Support.

izogfif
  • 6,000
  • 2
  • 35
  • 25
lukejkw
  • 1,054
  • 13
  • 19
  • 7
    downvote because this extension requires java, unlike XML Tools from Qub https://marketplace.visualstudio.com/items?itemName=qub.qub-xml-vscode – Devin Rhode Dec 19 '18 at 22:15
  • 3
    Unfortunately, now it is deprecated. Also agree with Devin that disadvantage is that it requires JDK or OpenJDK. – essential Oct 26 '20 at 17:43