Sam
Sam

Reputation: 61

Validating XSD itself

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.

Upvotes: 3

Views: 1879

Answers (4)

RutgerDOW
RutgerDOW

Reputation: 41

you can use xmllint for that:

xmllint --noout --dtdvalid http://www.w3.org/2001/XMLSchema.dtd my-schema.xsd

Upvotes: 2

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136002

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

Upvotes: 1

Madhusudan Joshi
Madhusudan Joshi

Reputation: 4476

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.

Upvotes: 1

Oded
Oded

Reputation: 499002

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.

Upvotes: 6

Related Questions