How to extract tag names from an XSD?
I need to write in Java. Is there any sample code available in t开发者_运维百科his regard?
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();
精彩评论