Generate .xsd Schema file from .xml file

When you are using JAXB(Java Architecture for XML Binding), you must require xml document to be converted into .xsd file. There is one Open Source called "trang" which does same thing. It takes .xml file as input and give .xsd as output. You can also use XMLSpy but It's not free. you will be provided 30 days trial.

1. Download "Trang"and Copy .jar files to local
2. Generate .xsd file using command as below using command prompt

java -jar trang.jar app-defaults.xml app-defaults.xsd

Note : app-defaults.xml is existing input .xml file and app-defaults.xsd is file which will generate after running this command.



app-defaults.xml
<?xml version="1.0" encoding="UTF-8"?>
<AppDefaults>
<RegionMasterURL>http://bitrazor.com/content/tivo/hme/trafficcam/RegionMaster.xml</RegionMasterURL>
<ShowTime>4500</ShowTime>
<FadeTime>750</FadeTime>
<DefaultRegion>97205</DefaultRegion>
</AppDefaults>

app-defaults.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="AppDefaults">
<xs:complexType>
<xs:sequence>
<xs:element ref="RegionMasterURL"/>
<xs:element ref="ShowTime"/>
<xs:element ref="FadeTime"/>
<xs:element ref="DefaultRegion"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="RegionMasterURL" type="xs:anyURI"/>
<xs:element name="ShowTime" type="xs:integer"/>
<xs:element name="FadeTime" type="xs:integer"/>
<xs:element name="DefaultRegion" type="xs:integer"/>
</xs:schema>

No comments:

Post a Comment