英文:
Define in XSD a list of byte arrays
问题
在我的DTO中,我有一个变量List<byte[]> attachmentList
,我想在XSD中对其进行建模。到目前为止,我有:
<xs:element name="attachmentList" type="AttachmentList">
</xs:element>
<!-- 更多代码在这里 -->
<!-- 字节数组的列表 -->
<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
中正确定义字节数组的列表?
英文:
In my DTO I have a variable List<byte[]> attachmentList
and I would likt to model it in XSD. So far I have:
<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>
Unfortunately, in the class generated by JAXB
it is then displayed as protected AttachmentList attachmentList;
, the AttachmentList
contains protected ByteArray documents;
and then finally the ByteArray
class contains protected List<Byte> byteArrayElement;
, which is also incorrect. How shall I correctly define in XSD
a list of byte arrays?
答案1
得分: 1
byte[]
的正确类型是xs:base64Binary
。
这意味着字段 List<byte[]> attachmentList
的XSD应该简单地是:
<xs:element name="attachmentList" type="xs:base64Binary" minOccurs="0" maxOccurs="unbounded"/>
英文:
The correct type for a byte[]
is xs:base64Binary
.
That means the XSD for a field List<byte[]> attachmentList
should simply be:
<xs:element name="attachmentList" type="xs:base64Binary" minOccurs="0" maxOccurs="unbounded"/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论