Multiple JAXB objects generated when converting XSD to Java

lplpaulg7

New Member
I am trying to use Spring with JAXB to convert an XSD/XML file to java JAXB objectsThe schema i am working with has fields as shown below:\[code\]<simpleType name="productType"> <restriction base="string"/></simpleType> <complexType name="child"> <sequence> <element name="product" type="productType" maxOccurs="unbounded"/> </sequence> </complexType><element name="products"> <complexType> <sequence> <element ref="child"/> </sequence> </complexType></element>\[/code\]When JAXB works with the above schema it generates two classes:\[code\]Products.javaChild.java\[/code\]Whith "Child" being an object inside the Products class as a list:\[code\]@XmlElement(required = true)protected List<Child> child;\[/code\]This is fine when converting an XML/XSD file to a JAXB object but when doing the conversion the other way round, i.e. converting a Hibernate or just a simple javabean to the JaxB object, it is very difficult to map the fields. In the above example, i have to first create the "Child" objects, put them in a list then create the "Product" Object. It seems like JAXB generates a class for each type i define in the XSD file.You can imagine how confusing this can get for a very large xml file with several level inner tags. Is it possible to generate a single JAXB object regardless of how many levels are in the xml file? (i.e. not create a separate class for each type defined in the XSD file.)
 
Back
Top