我有一个实体树,它是由hibernate获取的,我想从实体树生成xml。在这棵树中,有很多 blob 和 clob 数据类型。我不想将它们包含在 xml 中,而是想在 xml 中保留引用 id。 blob 和 clob 数据将存储在文件系统中我放置 xml 的同一目录中。
生成 xml 格式示例 -
<Address type="varchar" maxLength=”100”>
Los Angeles, CA 90067-6209, USA
</Address>
<Biography type="clob">
<!-- this clob data would be available in the same directory of this xml as a text file. Name format- [row_id]_biography -->
<ref id="44238185_biography"/>
</Biography>
<Image type="blob">
<!-- this blob data would be available in the same directory of this xml as a image file. Name format- [row_id]_image -->
<ref id="44238185_image"/>
</Image>
<DateCreated type="timestamp" format="yyyy-mm-dd hr:mm:ss">
18-04-13 05:12:34
</DateCreated>
我想知道大家怎么看待这个问题。
最佳答案
如何以 Base64 编码格式存储 BLOB 和 CLOB 数据?
如果您不想将 BLOB 和 CLOB 数据存储在文件系统中并引用它,您可以使用 base64 编码。 base64 编码的字符串稍后可用于从 xml 文件本身检索数据。
优点:
- 无需保留引用文献和其他文件。 XML 文件足以表示所有数据。
缺点:
- xml文件的大小会很大(取决于实际数据)。
- Base64 编码需要额外的处理。
关于java - 如何从保存 BLOB 和 CLOB 数据的实体树生成 Xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566060/