JAXB - XML Schema Types, Binary Data
Posted huey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAXB - XML Schema Types, Binary Data相关的知识,希望对你有一定的参考价值。
Data that has no "natural" representation with printable characters must, for inclusion in an XML file, still be represented in printable characters. The simple technique for this consists in converting the binary byte values to their hexadecimal representations. The XML Schema datatype to use in this case is xsd:hexBinary
. A sample schema declaration is shown below.
<xsd:complexType name="BinaryType"> <xsd:sequence> <xsd:element name="data" type="xsd:hexBinary"/> </xsd:sequence> </xsd:complexType>
The Java class produced by JAXB contains a convenient pair of getter and setter methods for accessing the instance variable (called data
) that stores the binary data. Its type and the type for passing the binary data is byte[]
. All conversions are handled by JAXB.
public class BinaryType { protected byte[] data; public byte[] getData() { return data; } public void setData(byte[] value) { this.data = ((byte[]) value); } }
以上是关于JAXB - XML Schema Types, Binary Data的主要内容,如果未能解决你的问题,请参考以下文章