You can load schemata quite easily with Xerces:
Just import the right classes:
import org.apache.xerces.util.*; import org.apache.xerces.xs.*; import org.apache.xerces.impl.xs.XMLSchemaLoader;
Instantiate the XSLoader implementation:
XMLSchemaLoader loader = new XMLSchemaLoader();
Setup the catalog:
String [] catalogs = { "catalog.xml" }; XMLCatalogResolver resolver = new XMLCatalogResolver(catalogs); loader.setEntityResolver(resolver);
Load the schema:
XSModel model = loader.loadURI(new File("myschema.xsd").toURI().toString());
For example, list all the types:
XSNamedMap map = model.getComponents(XSConstants.TYPE_DEFINITION); for (int j=0; j<map.getLength(); j++) { XSObject o = map.item(j); System.out.println("{"+o.getNamespace()+"}"+o.getName()); }
You can browse the javadoc for the package org.apache.xerces.xs at the apache website.