jaxb-ri
jaxb-ri copied to clipboard
Invalid Namespace set for Restrictions defined accross different Namespaces
In my current project we use XML schema files to define a web service interface. Often a base object is defined in one schema file (see below testSuper.xsd) and a use case specific restriction is defined in another schema file (see below test.xsd).
The generated XML encodes the restricted element (requestType) in the namespace of the base object (http://example.org/super) instead of the namespace of the restricted object (http://example.org/sub). The following sample illustrates the XML generated by JAXB:
<ns2:TestNode xmlns="http://example.org/super" xmlns:ns2="http://example.org/sub"> ns2:category <requestType>REQUEST</requestType> </ns2:category> </ns2:TestNode>
This XML doesn't validate against the schema using Eclipse 3.4 schema validation. Whereas the following XML output validates and is about what I expected:
<ns2:TestNode xmlns="http://example.org/super" xmlns:ns2="http://example.org/sub"> ns2:category ns2:requestTypeREQUEST</ns2:requestType> </ns2:category> </ns2:TestNode>
The XML schema definitions:
testSuper.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.org/super" targetNamespace="http://example.org/super" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:complexType name="ObjectCategory"> xs:sequence <xs:element name="requestType" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:schema>
test.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.org/sub" xmlns:super="http://example.org/super" targetNamespace="http://example.org/sub" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:import namespace="http://example.org/super" schemaLocation="testSuper.xsd"/> <xs:element name="TestNode"> xs:complexType xs:sequence <xs:element name="category" type="SubObjectCategory" /> </xs:sequence> </xs:complexType> </xs:element> <xs:simpleType name="SubRequestType"> <xs:restriction base="xs:string"> <xs:enumeration value="REQUEST"/> <xs:enumeration value="RESPONSE"/> </xs:restriction> </xs:simpleType> <xs:complexType name="SubObjectCategory"> xs:complexContent <xs:restriction base="super:ObjectCategory"> xs:sequence <xs:element name="requestType" type="SubRequestType"/> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> </xs:schema>
Best regards -dani
Environment
Operating System: All Platform: All
Affected Versions
[2.1.11]
- Issue Imported From: https://github.com/javaee/jaxb-v2/issues/662
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @glassfishrobot
@glassfishrobot Commented Reported by dkaeppeli
@glassfishrobot Commented snajper said: Thanks for report, we'll try to look at it for 2.2.
@glassfishrobot Commented snajper said: Adjusting priority of the issue.
@glassfishrobot Commented snajper said: Reassigning to myself.
@glassfishrobot Commented snajper said: Waiving for Metro 2.0, need to find TCK friendly solution.
@glassfishrobot Commented snajper said: Adjusting priority based on waiver.
@glassfishrobot Commented Was assigned to snajper
@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-662