2

If I have the following schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="test" xmlns="test" version="1.0" elementFormDefault="unqualified" attributeFormDefault="unqualified">
    <xs:element name="testType" type="testType"/>
    <xs:complexType name="testType" abstract="true">
        <xs:sequence>
            <xs:element name="testField" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="testSubType">
        <xs:complexContent>
            <xs:extension base="testType">
                <xs:sequence>
                    <xs:element name="someField" type="xs:string"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>

which is used to validate this instance document:

<n1:testType xsi:type="n1:testSubType" xsi:schemaLocation="test test%20schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n1="test">
    <testField>String</testField>
    <someField>String</someField>
</n1:testType>

I'm getting an error when unmarshalling stating: unrecognized type name: {test}testSubType. Did you mean testSubType? How can I use JAXB to unmarshal a subclass of an abstract base class which uses the xsi:type attribute containing the namespace prefix?

Update: Unmarshalling works when the namespace prefix is removed from the xsi:type attribute. However, the instance document will no longer be valid according to schema. The schema needs the targetNamespace declared, so changing that isn't an option.

holic87
  • 791
  • 2
  • 17
  • 29
  • 1
    Nevermind, I figured it out: I had to add a `namespace` parameter to the `@XmlType` annotations in my Java classes for `TestType` and `TestSubType`. For example `@XmlType(namespace="test")`. – holic87 Oct 12 '11 at 23:27

0 Answers0