I\'m writing an XML schema (an XSD) to describe the format our partners should send us data in.
And I\'m having a hard time finding a tool that can validate the XSD sche
The W3C has a online validator for XML Schemas at http://www.w3.org/2001/03/webdata/xsv. Since W3C is the source of the XML Schema spec, their validator should be trustworthy.
cd /the/dir/with/your/schema
curl -O https://www.w3.org/2012/04/XMLSchema.xsd
xmllint.exe --noout --schema XMLSchema.xsd <your schema>
In *nix (including git-bash or similar on Windows), if the schema is valid then $? == 0
else $? == 1
. I'm sure there is some powershell equivalent ...
This came from a comment by @AlexanderKjäll to an answer by @lavinio elsewhere here. I added my own comment to say @AlexanderKjäll should add this as an answer. However (for me atleast), it wasn't quite correct since it won't work using the remote file URI. And thus my answer. If you upvote this could you please upvote their comment.
So, how should I validate an XML schema (XSD)?
The question you ask is a good one. Just "winging it" is likely to get you in trouble. From the Wikipedia article XML Schema Editor (emphasis mine):
The [W3C XML Schema] standard is versatile, allowing for programming concepts such as inheritance and type creation, but it is complex. The standard itself is highly technical and published in 3 different parts, making it difficult to understand without committing large amounts of time.
So, given the complexity of the W3C XML Schema standard, how do you ensure that a schema that you create complies with that standard? From the same Wikipedia article:
The problems users face when working with the XSD standard can be mitigated with the use of graphical editing tools. Although any text-based editor can be used to edit an XML Schema, a graphical editor offers advantages; allowing the structure of the document to be viewed graphically and edited with validation support, entry helpers and other useful features.
At the bottom of that Wikipedia article you'll find a list of XML schema editors, some of which are licensed as "free software."
the Java SDK comes with a standard tool called xjc . This tool generates the classes parsing your schema. You could use this code to validate your partners' input.
See also : http://www.java2s.com/Tutorial/Java/0440__XML/ThexjcTool.htm
If this is a short-term thing, you could use an evaluation copy of a tool like Stylus Studio.
If it's long-term maintenance, you might want to consider purchasing an XML schema editor like Stylus, or Oxygen or Altova.
You didn't specify the source language, but it's only a few lines of code to write a schema validator in Java or .Net.