如何在 XML 中嵌入二进制数据? [英] How do you embed binary data in XML?
问题描述
我有两个用 Java 编写的应用程序,它们通过网络使用 XML 消息相互通信.我在接收端使用 SAX 解析器从消息中取回数据.要求之一是在 XML 消息中嵌入二进制数据,但 SAX 不喜欢这样.有人知道怎么做吗?
更新:我使用 apache commons codec library 中的 Base64 类,以防其他人正在尝试类似的方法.
您可以使用 base64 对二进制数据进行编码并将其放入 Base64 元素中;下面的文章是关于这个主题的一篇很好的文章.
I have two applications written in Java that communicate with each other using XML messages over the network. I'm using a SAX parser at the receiving end to get the data back out of the messages. One of the requirements is to embed binary data in an XML message, but SAX doesn't like this. Does anyone know how to do this?
UPDATE: I got this working with the Base64 class from the apache commons codec library, in case anyone else is trying something similar.
You could encode the binary data using base64 and put it into a Base64 element; the below article is a pretty good one on the subject.
Handling Binary Data in XML Documents
这篇关于如何在 XML 中嵌入二进制数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!