How to validate an XML schema i.e. Validate an XSD file
Joined: Jul 27, 2005
I need to validate an XML schema, please note I am not talking about validating an XML document against a schema. I would like to validate the XSD and in addition to validating my XSD i would like to make sure that it is a subset of a large schema. Any ideas on how to do this?
SCJP 1.4, SCWCD 1.4
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999
Joined: Apr 16, 2008
An XML Schema is an XML-based document and the process to validate an instance is the same as for any other XML-based document. Is there something that you don't understand about XML validation using XML schema?
Joined: Jul 27, 2005
Jimmy thanks for your reply.
I'll give you more information on what I am trying to do. I have created a subset of a parent schema i.e. http://www.landxml.org/schema/LandXML-1.2/LandXML-1.2.xsd. My new custom schema is based on this one. What I would like to do is programmatically make sure that all XML files based on my schema pass validation against my schema and the parent schema. And I think if I could somehow validate my manually created schema against the parent one, I will not have to validate XML files against both schemas?
Does this make sense or am I going about this wrong?
Author and all-around good cowpoke
Joined: Mar 22, 2000
Sounds like you should be getting familiar with the javax.xml.validation package.
You should be able to use it to - for example, - locate all .xml files in a directory and validate versus a schema.
Ola, your concept of "subset" and "parent" are off a bit. XML Schemas are not object-oriented and there is no concept of "subset" or "parent." During execution, there is only one XML schema and one XML document. The XML schema can be composed of many files using include and import statements, but conceptually there is only one XML Schema.
So, it sounds like you have created a customized XML schema based on the one at landxml.org. Your customized schema must not include any design changes that conflict with the XML schema at landxml.org if you want your XML documents to validate successfully with both XML Schemas. If your design changes conflict with the XML schema at landxml.org, then there is no way to have your XML documents validate successfully with both of them.
You have to analyze the reasons why your have created a customized XML schema and you have to analyze why you need to be able to validate against the landxml.org XML schema.
And I think if I could somehow validate my manually created schema against the parent one, I will not have to validate XML files against both schemas?
Since your XML documents will contain markup that is not defined in the landxml.org XML Schema, you will never be able to validate your document with the landxml.org XML Schema. This is not possible.
XML Schemas are used to define an XML markup language. If you create your own XML Schema with additonal elements and attibutes and/or restructure something defined in a different XML schema, you essentially have created a new markup language.