tags:

views:

53

answers:

4

Anybody knows Java API to parse XSD schema file? I found XSOM (https://xsom.dev.java.net) but I doesn't seem to maintained anymore.

+1  A: 

We have tended to use Apache Xerces http://xerces.apache.org/. Works really well for us.

Chris Aldrich
Just parse XSD file? Such approach is very complicated when your schema file contains many compound and complex types declarations.
Henryk Konsek
A: 

As mentioned, a schema is itself valid XML. What do you want to load it for, validation? If so then there are some handy classes in the javax.xml.validation package.

Qwerky
For validation, but not for validation of the XML file. I need to extract all data types from XSD and then export restrictions associated with the elements to external validation system.
Henryk Konsek
+1  A: 

JAXB

See this question

Marcus
Or take a look at JAXP (https://jaxp.dev.java.net/)
Marcus
I don't want XML binding nor to parse XSD by hand (i.e. with JAXP). I need API to browse XSD structure, list types defined in the Schema and all restrictions associated with them. I know I can parse XSD with JAXP but for very complex schemas is may be pain in the a*s.
Henryk Konsek
As others have said, XSD is just a valid XML doc. Use a DOM parser, if you're going to update it or need to navigate it in non-sequential order. A SAX parser would be very efficient if you want to extract elements in sequential order, and it shouldn't be difficult to write, even for long/complex xml - especially if you're just extracting the types and restrictions.And from the comment you made in your original post, I think you're better off just writing a SAX parser, and converting it to your in-house validation rules.
Marcus
A: 

Depends what your specific requirements are. This page gives a good overview of the major options and the use cases they support.

One thing to think about: Depending on the platform you are deploying to and other frameworks you are using, there may already be various APIs in your dependency tree (xerces is particularly common in App Servers for example). Watch out for version conflicts which can be a nightmare to isolate and debug.

Andrew Harmel-Law
If you stick with the standard APIs you are much safer. For example deal with Xerces as a JAXP parser instead of native APIS. This way if you port to another framework and they are using another JAXP implementation you're still safe.
Blaise Doughan
Please refer to the comment I wrote to the question. I don't need XML parsing API.
Henryk Konsek