Reputation: 91
I need to write in Java. Is there any sample code available in this regard?
Upvotes: 0
Views: 683
Reputation: 5843
You could use Apache XmlSchema library (http://ws.apache.org/commons/xmlschema14).
The idea is to create the instance of XmlSchema class that represents your schema:
InputStream is = new FileInputStream(fileName);
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
XmlSchema schema = schemaCol.read(new StreamSource(is), null);
and use it to obtain information about elements and types specified by your schema. You could for instance enlist all element names:
XmlSchemaObjectTable objTable = schema.getElements();
Iterator elementNames = objTable.getNames();
Upvotes: 1