首页 > 解决方案 > 在 XSD 中定义一个字节数组列表

问题描述

在我的 DTO 中,我有一个变量List<byte[]> attachmentList,我想在 XSD 中对其进行建模。到目前为止,我有:

                    <xs:element name="attachmentList" type="AttachmentList">
                    </xs:element>

<!-- more code goes here -->


<!-- List of ByteArrays -->
    <xs:complexType name="AttachmentList">
    <xs:sequence>
        <xs:element name="documents" type="ByteArray" nillable="true">
        </xs:element>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="ByteArray">
    <xs:sequence>
        <xs:element maxOccurs="unbounded" name="byteArrayElement" type="xs:byte"/>
    </xs:sequence>
</xs:complexType>

不幸的是,在JAXB它生成的类中,然后显示为protected AttachmentList attachmentList;AttachmentList包含protected ByteArray documents;,最后是ByteArray类包含protected List<Byte> byteArrayElement;,这也是不正确的。XSD我应该如何在字节数组列表中正确定义?

标签: javaxsdjaxb

解决方案


a 的正确类型byte[]xs:base64Binary.

这意味着字段的 XSDList<byte[]> attachmentList应该是:

<xs:element name="attachmentList" type="xs:base64Binary" minOccurs="0" maxOccurs="unbounded"/>

推荐阅读