在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类包含{ {1}},这也是不正确的。我应该如何在protected List<Byte> byteArrayElement;中正确定义一个字节数组列表?

解决方法

byte[]的正确类型是xs:base64Binary

这意味着字段List<byte[]> attachmentList的XSD应该简单地是:

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