Community
Participate
Working Groups
From: http://stackoverflow.com/questions/4460158/generating-schema-with-default-minoccurs-using-moxy/4464124#4464124 The following schema should be created: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="root"> <xs:sequence> <xs:element name="duration" type="xs:int" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:schema> Instead of: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="root"> <xsd:all> <xsd:element name="duration" type="xsd:int"/> </xsd:all> </xsd:complexType> </xsd:schema> For the following code: package minoccurs; import java.io.IOException; import javax.xml.bind.JAXBContext; import javax.xml.bind.SchemaOutputResolver; import javax.xml.bind.annotation.XmlType; import javax.xml.transform.Result; import javax.xml.transform.stream.StreamResult; import org.eclipse.persistence.Version; public class Demo { @XmlType(propOrder = {}) public static class Root { private Integer duration; public Integer getDuration() { return duration; } public void setDuration(Integer duration) { this.duration = duration; } } public static class MySchemaOutputResolver extends SchemaOutputResolver { @Override public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException { StreamResult result = new StreamResult(System.out); result.setSystemId(suggestedFileName); return result; } } public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); System.out.println(jc); System.out.println(Version.getVersionString()); jc.generateSchema(new MySchemaOutputResolver()); } }
Created attachment 185459 [details] MOXy - Fix
Created attachment 185554 [details] MOXy - Test Cases
Created attachment 185555 [details] MOXy - Fix
Correction to bug statement. The following is what should be generated: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="root"> <xs:all> <xs:element name="duration" type="xs:int" minOccurs="0"/> </xs:all> </xs:complexType> </xs:schema> Fix checked into trunk at rev: 8728 Code reviewed by: David McCann Removed check that explicitly prevented minOccurs=0 from being written on elements declared within an all block.
Fixed as per above comments.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink