volcano
volcano

Reputation: 91

How to extract tag names from an XSD?

I need to write in Java. Is there any sample code available in this regard?

Upvotes: 0

Views: 683

Answers (1)

Tomasz Blachowicz
Tomasz Blachowicz

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

Related Questions