I have the elements to create XSD in the DB. such as a
sample row would be..

 XSD_TAG   XSD_DATATYPE  TYPEDEF  MAXBOUND  MINBOUND  PARENT
          reject        string     basic     null       null    sources

so basically says that one of the tags to be constructed would be reject and it is of type string.
the resulting tag after construction of the xsd should be
<xs:element name="reject" type="xs:string" nillable="true"/>
and since it has a parent tag sources

 <xs:complexType name="sources"> 
              <xs:sequence>
              <xs:element name="reject" type="xs:string" nillable="true"/>
              </xs:sequence>
            </xs:complexType> 

The header of the xsd should be generated as follows:

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
               <xs:schema xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
               jxb:version="1.0">
           </xs:schema>

In order to fetch the element name or the Complex type name, a Java bean is used with appropriate getters and setters.
So since the complete structure of the xsd is stored in DB, by getting the List of that bean, we can fetch each element and its properties to be constructed.

The Bean has the following elements mapping to the table columns.

public class TestXsdTable extends HrdhDatedEntry {


        /** 
         */
        private static final long serialVersionUID = -193670018802945645L;

        @NotEmpty
        @Size(max = ValidationConstants.MAX_LENGTH_20)
        private String  cJobNm;

        @Size(max = ValidationConstants.MAX_LENGTH_20)
        private String dbFieldName;

        @Size(max = ValidationConstants.MAX_LENGTH_20)
        private String colDatType;

        private String xsdDoc;

        @Size(max = ValidationConstants.MAX_LENGTH_20)
        private String xsdTag;


        @Size(max = ValidationConstants.MAX_LENGTH_30)
        private String xsdDataType;


        @Size(max = ValidationConstants.MAX_LENGTH_30)
        private String xsdDefVal;

        @Size(max = ValidationConstants.MAX_LENGTH_15)
        private String typedef;

        @Size(max = ValidationConstants.MAX_LENGTH_10)
        private String maxbound;

        @Size(max = ValidationConstants.MAX_LENGTH_10)
        private String minbound;

        @Size(max = ValidationConstants.MAX_LENGTH_1)
        private String isnillable;

        @Size(max = ValidationConstants.MAX_LENGTH_1)
        private String isparent;

        @Size(max = ValidationConstants.MAX_LENGTH_50)
        private String parent;

        private String xsdView;  

with appropriate getters and setters.

How can I get the structure of the xsd as I described above.

 <xs:schema xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" jxb:version="1.0">
           <xs:complexType name="sources">   
          <xs:sequence>
              <xs:element name="reject" type="xs:string" nillable="true"/>
          </xs:sequence>
        </xs:complexType>
        </xs:schema>

I tried so many approaches but am not able to get this structure printed. Please guide me. so basically the method should take the java object and retrieve the values to build the xsd.

Please advice.

Could someone put some code or direct me to a code that will generate the schema as I mentioned at the end of my post. I have tried so many approaches, since few days, one of the approaches I tried was using Eclipse EMF approach, but that is printing some junk data. Kindly help me... Thanks.

The xsd that I posted at the end is not the complete one, but a part of it, where I showed how the "sources" should be created by fetching the data from the DB. The xsd has other elements to be constructed and has about 10 rows in DB.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.