Tool for validating xml with xml schema
For that reason, I’ve cobbled together a Java program to solve this issue.
Judging by the popularity of this question on Stack Overflow (and my answer), it seems that a lot of people struggle to check the validity of an XML file against an XML Schema.It’s a shame that what should be a trivial task has wasted hours of developer’s lives.In this article I’ll try to offer a few alternatives for various platforms and hopefully make things a bit simpler.There are actually a few different options at your disposal (which is probably part of the problem).If you don’t have it installed, you can use your package manager to install libxml2 or grab it from The major issue with xmllint is that it doesn’t support the whole of the XML Schema standard (which is large and complex).
For this reason you may want to double check with another validator (I find xmllint’s error messages and ease of use make it very useful when rapidly iterating during development of XML/XSD files). It exists in both C and Java versions (I believe a customised version of Xerces is bundled in the Sun JDK).
However, there isn’t a simple way to immediately run the Xerces validator from the command line.
We’ll start by looking at what is probably the fastest and easiest option to get started with validation: A web search reveals the Core Filing XML Schema Validator and the Free Formatter Validator amongst others.
The Core Filing offering only allows uploading of files, whereas Free Formatter allows either pasting of documents or pointing to URLs (but not uploading files! Both work fine and seem to use the Apache Xerces parser underneath the hood, which I’ll talk more about in the next section.
The problem with on-line validation is that it will quickly get frustrating if you are doing a lot of validating and need a quick turn-around time. For Mac and Linux users, you likely already have xmllint installed, which can do validation.
There may also be privacy or file size reasons which mean you can’t use an on-line validator. At a terminal type: flag or the XML file will be printed to standard out along with the validation results.