|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Schema generation problem with JAXBHi,
I am using annotations to customize the XML schema generated by JAXB. I have a scenario where there are multiple occurances of the same element name "product" but not at the same level. In the example below I have a "product" under "Result" which is of type "ProductA". I also have a "product" under "Store" which is of type "ProductB". But the schema generated by JAXB creates a single "product" with type "xs:anyType" (In schema1.xsd). This is causing problem during marshalling and unmarshalling. Is there a way to configure JAXB to not use references ([i]<xs:element ref="ns1:product"/>[/i]) to other schema but rather define the element in the main schema itself (like: [i]<xs:element name="product" type="productA" minOccurs="0"/>[/i])?? That would solve my problem. [u]Following are the java files being used for this example:[/u] [b]1) ProductA.java:[/b] public class ProductA { } [b]2) ProductB.java:[/b] public class ProductB { } [b]3) Store.java:[/b] @XmlType(name = "Store") public class Store { private ProductB product; @XmlElement(name = "product", type = ProductB.class, required = true, namespace = "java:com.test") public ProductB getProduct() { return product; } public void setProduct(ProductB product) { this.product = product; } } [b]4) Result.java:[/b] @XmlType(name = "Result") public class Result { private ProductA product; private Store store; @XmlElement(name = "product", type = ProductA.class, required = true, namespace = "java:com.test") public ProductA getProduct() { return product; } public void setProduct(ProductA product) { this.product = product; } @XmlElement(name = "store", required = true, namespace = "java:com.test") public Store getStore() { return store; } public void setStore(Store store) { this.store = store; } } [u]Following are the schema files generated by JAXB:[/u] [b]1) schema1.xsd:[/b] <xs:schema version="1.0" targetNamespace="java:com.test" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import schemaLocation="schema2.xsd"/> <xs:element name="product" nillable="true" type="xs:anyType"/> <xs:element name="store" type="Store"/> </xs:schema> [b]2) schema2.xsd:[/b] <xs:schema version="1.0" xmlns:ns1="java:com.test" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import namespace="java:com.test" schemaLocation="schema1.xsd"/> <xs:complexType name="Store"> <xs:sequence> <xs:element ref="ns1:product"/> </xs:sequence> </xs:complexType> <xs:complexType name="productB"> <xs:sequence/> </xs:complexType> <xs:complexType name="Result"> <xs:sequence> <xs:element ref="ns1:product"/> <xs:element ref="ns1:store"/> </xs:sequence> </xs:complexType> <xs:complexType name="productA"> <xs:sequence/> </xs:complexType> </xs:schema> In other words is it possible to configure JAXB to not generate multiple schemas but to generate just one schema file? Thanks for your time and I appreciate any suggestions. [Message sent by forum member 'sudhirbabu' (sudhirbabu)] http://forums.java.net/jive/thread.jspa?messageID=354548 --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free embeddable forum powered by Nabble | Forum Help |