I am trying to map a java model into some XML. To do this I am using the MOXy implementation of JAXB. I have run into some troubles generating a valid XML Schema from the java model. I use the following model:
@XmlRootElement
public class FooBar {
@XmlAttribute
@XmlPath("test/@foo")
private boolean foo;
}
And I am generating the schema with the following code:
public static void main(String[] args) throws Exception {
final SchemaOutputResolver sor = new SchemaOutputResolver() {
@Override
public Result createOutput(String namespaceUri,
String suggestedFileName) throws IOException {
return new StreamResult(System.out);
}
};
JAXBContext jc = JAXBContext.newInstance(FooBar.class);
jc.generateSchema(sor);
}
And I use the following package-info.java file:
@XmlSchema(namespace = "http://moxy.test", elementFormDefault = XmlNsForm.QUALIFIED)
package test.moxy;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
When running the test I obtain the following schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:ns0="http://moxy.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://moxy.test" elementFormDefault="qualified">
<xsd:complexType name="big">
<xsd:sequence>
<xsd:element name="test" minOccurs="0">
<xsd:complexType>
<xsd:sequence/>
<xsd:attribute ref="ns0:foo"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="big" type="ns0:big"/>
<xsd:attribute name="foo" type="xsd:boolean" use="required"/>
</xsd:schema>
It can be seen that the last attribute element is not what one would expect. If I remove the package-info.java file, the following schema is generated:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="fooBar">
<xsd:sequence>
<xsd:element name="test" minOccurs="0">
<xsd:complexType>
<xsd:sequence/>
<xsd:attribute name="foo" type="xsd:boolean" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="fooBar" type="fooBar"/>
</xsd:schema>
Which is what I would expect being generated. Does anyone know why this is the case?
UPDATE
This issue (https://bugs.eclipse.org/354130) has now been fixed in our EclipseLink 2.3.1 and 2.4.0 streams, and will be available from our nightly download site starting August 9th, 2011: