I have a class which contains inner enum type.
@XmlRootElement
public class Address {
@XmlEnum
@XmlType(name="addressType")
public static enum Type {
}
}
Here is my package-info.java
.
@XmlSchema(
attributeFormDefault = XmlNsForm.UNQUALIFIED,
elementFormDefault = XmlNsForm.QUALIFIED,
namespace = "http://some",
xmlns = {
@XmlNs(prefix = "xsi",
namespaceURI = XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI)
}
) @XmlAccessorType(XmlAccessType.NONE)
package some;
It works find when I use JAXBContex#generateSchema.
But org.codehaus.mojo:jaxb2-maven-plugin:schemagen generates separate schemas.
One for address
which has a namespace,
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="..."
targetNamespace="...">
<xs:complexType name="address">
...
<xs:sequence>
...
<xs:element name="type" type="addressType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
and the other for addressType
which has no namespace.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
<xs:simpleType name="addressType">
<xs:restriction base="xs:string">
<xs:enumeration value="CC"/>
<xs:enumeration value="BCC"/>
<xs:enumeration value="TO"/>
<xs:enumeration value="REPLY_TO"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Which one is right?
The XML schema generator schemagen
which comes along with JAXB (and JDK) generates two .xsd files from class Address (as shown), very much like the ones you have posted as output from the maven plugin. However, the first .xsd file contains
<xs:import schemaLocation="schema2.xsd"/>
which is not in your first .xsd. Did you remove this element? With this element, there is no reason to doubt the pair of .xsd files.
It would have been nice to see the single .xsd file.
You can also use xjc to generate Java classes from the .xsd files and compare the results.