jaxb2-maven-plugin icon indicating copy to clipboard operation
jaxb2-maven-plugin copied to clipboard

References to simpletypes are created without namespace prefix (schemagen)

Open umefjord opened this issue 5 years ago • 0 comments

When running schemagen for a project with enum types the generated XSD contains no namespace prefix in the elements with references to these types. As no default namespace is declared in the root xjc will not accept the generated XSD.

Example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vh="http://schemas.acme.com/vehicles" elementFormDefault="qualified" targetNamespace="http://schemas.acme.com/vehicles" version="1.0">

	<xs:simpleType name="CarType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="SEDAN"/>
			<xs:enumeration value="STATION_WAGON"/>
			<xs:enumeration value="SUV"/>
			<xs:enumeration value="HATCHBACK"/>
			<xs:enumeration value="CABRIOLET"/>
		</xs:restriction>
	</xs:simpleType>

	<xs:complexType name="Car">
		<xs:sequence>
			<xs:element ref="CarType"/>
		</xs:sequence>
	</xs:complexType>

</xs:schema>

Since <xs:element ref="CarType"/> contains no namespace prefix (i.e. "vh:CarType") and the root element contains no default namespace declaration, the XJC-command will fail with:

src-resolve.4.1: Error resolving component 'CarType'. It was detected that 'CarType' has no namespace, but components with no target namespace are not referenceable from schema document 'file:/...'. If 'CarType' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'CarType' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:/...'.

umefjord avatar Aug 20 '19 08:08 umefjord