Java Reference
In-Depth Information
Generating an XSD File from Sample XML Messages
Now you can generate the XSD file from the preceding sample XML messages. Most popular XML tools
and enterprise Java IDEs can generate an XSD file from a couple of XML files. Here, I have chosen
Apache XMLBeans ( http://xmlbeans.apache.org/ ) to generate my XSD file.
Note You can download Apache XMLBeans (e.g., v2.4.0) from the Apache XMLBeans web site and extract it to
a directory of your choice to complete the installation.
Apache XMLBeans provides a tool called inst2xsd for generating XSD files from XML instance files.
It supports several design types for generating XSD files. The simplest is called Russian doll design , which
generates local elements and local types for the target XSD file. Because there's no enumeration type
used in your XML messages, you should also disable the enumeration generation feature. You can
execute the following command to generate the XSD file for your data contract:
inst2xsd -design rd -enumerations never request.xml response.xml
The generated XSD file will have the default name schema0.xsd , located in the same directory. Let's
rename it to temperature.xsd .
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace=" http://springenterpriserecipes.apress.com/weather/schemas"
xmlns:xs=" http://www.w3.org/2001/XMLSchema">
<xs:element name="GetTemperaturesRequest">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="city" />
<xs:element type="xs:date" name="date"
maxOccurs="unbounded" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetTemperaturesResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="TemperatureInfo"
maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:float" name="min" />
<xs:element type="xs:float" name="max" />
<xs:element type="xs:float" name="average" />
Search WWH ::




Custom Search