使用XSD定义一个字节数组列表。

huangapple go评论80阅读模式
英文:

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&lt;Byte&gt; byteArrayElement;,这也是不正确的。您应该如何在XSD中正确定义字节数组的列表?

英文:

In my DTO I have a variable List&lt;byte[]&gt; attachmentList and I would likt to model it in XSD. So far I have:

                    &lt;xs:element name=&quot;attachmentList&quot; type=&quot;AttachmentList&quot;&gt;
                    &lt;/xs:element&gt;

&lt;!-- more code goes here --&gt;


&lt;!-- List of ByteArrays --&gt;
    &lt;xs:complexType name=&quot;AttachmentList&quot;&gt;
    &lt;xs:sequence&gt;
        &lt;xs:element name=&quot;documents&quot; type=&quot;ByteArray&quot; nillable=&quot;true&quot;&gt;
        &lt;/xs:element&gt;
    &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;

&lt;xs:complexType name=&quot;ByteArray&quot;&gt;
    &lt;xs:sequence&gt;
        &lt;xs:element maxOccurs=&quot;unbounded&quot; name=&quot;byteArrayElement&quot; type=&quot;xs:byte&quot;/&gt;
    &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;

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&lt;Byte&gt; byteArrayElement;, which is also incorrect. How shall I correctly define in XSD a list of byte arrays?

答案1

得分: 1

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

这意味着字段 List&lt;byte[]&gt; attachmentList 的XSD应该简单地是:

&lt;xs:element name=&quot;attachmentList&quot; type=&quot;xs:base64Binary&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/&gt;
英文:

The correct type for a byte[] is xs:base64Binary.

That means the XSD for a field List&lt;byte[]&gt; attachmentList should simply be:

&lt;xs:element name=&quot;attachmentList&quot; type=&quot;xs:base64Binary&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/&gt;

huangapple
  • 本文由 发表于 2020年9月17日 02:26:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63925938.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定