3

Could anyone please tell me how to validate an XSD file itself (not XML against XSD)? I have checked many forums and sites (including SO) and most of them refers some or the other online validator. But this is not a one-time check for us. Our application involves an XSL transformation using an XSD, so we need to determine whether the XSD to be used is itself in a valid format or not, as in, all the tags match, with a starting and a closing one. Certain tags aren't allowed as a child tag, etc. That's why we need a proper java code to achieve the same.

Any help would be highly appreciated.

Sam
  • 61
  • 9

4 Answers4

4

You can validate an XSD file against the w3 XSD schema that can be found here.

Use the same validation techniques you validate any other XML file with an XSD file, only the source document would be your XSD file.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
2

you can use xmllint for that:

xmllint --noout --dtdvalid http://www.w3.org/2001/XMLSchema.dtd my-schema.xsd
RutgerDOW
  • 41
  • 2
1

You can validate your XSD online here.

Just copy and paste your XSD here and click on validate Schema , it will give you the result.

Madhusudan Joshi
  • 4,438
  • 3
  • 26
  • 42
1

You can try javax.xml.validation package

SchemaFactory f = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema s = f.newSchema(new File("1.xsd"));

Schema.newSchema() API

Parses the specified File as a schema and returns it as a Schema
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • Thank you everyone for your respective inputs. All 3 of them worked fine, but like I mentioned, we don't need anything that'd be outside the application, i.e. on some other domain. If their URL changes tomorrow, we shouldn't have to go back to the code. Hence, marking the 3rd one as answer, as its the most relevant and works well. – Sam May 13 '13 at 17:08