<complexType name="spThread">
<sequence>
<element name="SPThreadID" type="int" />
<element name="durtime" minOccurs="0" default="0">
<simpleType>
<restriction base="int">
<minInclusive value="0" />
</restriction>
</simpleType>
</element>
<element name="minexecutions" minOccurs="0" default="0">
<simpleType>
<restriction base="int">
<minInclusive value="0" />
</restriction>
</simpleType>
</element>
<element name="numThreads" type="int" />
<element name="procedures" type="spm:procedure" minOccurs="1"
maxOccurs="unbounded" />
</sequence>
</complexType>
i want to generate this type of .xsd file using java code..? How can i do that.?
Specially how to generate Simple type elements and put restrictions on it ?
You can use any XML-handling API to achieve this. JDOM is one of them. If you'd like an API specific to building XML Schemas which you then serialize into XML, you might want to check out Eclipse MDT API.
You can use Java2Schema tool for generating schema from java classes, and also you can try JaxB 2.0
I recommend you JAXB to any XML jobs you do. But normally XSD files are generated manually and then XML files are generated programatically using the XSD files. What are you trying to develop?
Instead of creating your own simple type to represent integers starting with
0
, you could leverage the existingxs:nonNegativeInteger
type. I'll demonstrate with an example.SpThread
You can use the
@XmlSchemaType
annotation to specify what type should be generated in the XML schema for a field/property.Demo
You can use the
generateSchema
method onJAXBContext
to generate an XML schema:Output
Below is the XML schema that was generated.