How to create an XSD file using XML Data in java -


i have xml data like

<data><customerdetails><customername>abcd</customername><cusomeracctnumber>12121212</cusomeracctnumber></customerdetails><billdetails><billtxdetails><billid>121212</billid><billdate>12-may-2015</billdate><time>12:55am</time></billtxdetails><billtxdetails><billid>121212</billid><billdate>12-may-2015</billdate><time>5:55am</time></billtxdetails></billdetails></data> 

how create xsd file using java? , how create java class (pojo/bean) above xml data? tried way public class customerdetails{private string customername;private string cusomeracctnumber;==>setters , getters}public class billtxdetails{private string billid;private string billdate;private string time;==>setters , getters} public static void main(sring ....){class[] c = {customerdetails.class, billtxdetails.class};jaxbcontext jc =jaxbcontext.newinstance(data.class);jc.generateschema(new schemaoutputresolver() {@override public result createoutput(string namespaceuri, string suggestedfilename) throws ioexception {streamresult result = new streamresult(system.out);result.setsystemid(suggestedfilename); return result }}); }but still iam not getting in xsd root element thanks

if using eclipse u can following.

  • create xml file in project.
  • right click on xml file click generate schema.
  • give name

i got following when trying generate schema xml

<?xml version="1.0" encoding="utf-8"?><xsd:schema   xmlns:xsd="http://www.w3.org/2001/xmlschema">   <xsd:element name="billdetails">     <xsd:complextype>       <xsd:sequence>         <xsd:element maxoccurs="unbounded" ref="billtxdetails"/>       </xsd:sequence>     </xsd:complextype>   </xsd:element>   <xsd:element name="data">     <xsd:complextype>       <xsd:sequence>         <xsd:element ref="customerdetails"/>         <xsd:element ref="billdetails"/>       </xsd:sequence>     </xsd:complextype>   </xsd:element>   <xsd:element name="customerdetails">     <xsd:complextype>       <xsd:sequence>         <xsd:element ref="customername"/>         <xsd:element ref="cusomeracctnumber"/>       </xsd:sequence>     </xsd:complextype>   </xsd:element>   <xsd:element name="time" type="xsd:string"/>   <xsd:element name="billtxdetails">     <xsd:complextype>       <xsd:sequence>         <xsd:element ref="billid"/>         <xsd:element ref="billdate"/>         <xsd:element ref="time"/>       </xsd:sequence>     </xsd:complextype>   </xsd:element>   <xsd:element name="billid" type="xsd:string"/>   <xsd:element name="billdate" type="xsd:string"/>   <xsd:element name="customername" type="xsd:string"/>   <xsd:element name="cusomeracctnumber" type="xsd:string"/>   </xsd:schema> 

then right click on xsd , select generate java classes


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -