开发者

JAXB: error unmarshalling element containing xsi:type with namespace

开发者 https://www.devze.com 2023-04-12 20:20 出处:网络
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\" attributeFormDef

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 c开发者_如何学Gohanging that isn't an option.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号