aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to validate an XML schema i.e. Validate an XSD file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to validate an XML schema i.e. Validate an XSD file" Watch "How to validate an XML schema i.e. Validate an XSD file" New topic
Author

How to validate an XML schema i.e. Validate an XSD file

Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
Hi all,

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?

thanks.


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
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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?
Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
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?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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.

Bill
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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.

Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
Thanks for that explanation Jimmy.

I appreciate it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to validate an XML schema i.e. Validate an XSD file