Embbed an image in xml file
I am exporting some data from my database in xml format. The file exported has an extension as .xml and it is viewed as Excel f开发者_如何学JAVAile. I want to insert an image in this xml file so that when we view it as Excel we will be able to see the image along with the data. Whatever I have found from the internet is that there is no straight forward way to insert an image in xml file as xml file were designed for handling the data. Can any one tell me what is the approach I will have to follow in order to obtain the desired functionality.
xml files are text files, and you can embedd binary data if you encode it with Base64 algorithm.
But to view the image you will need to decode the Base64-string and pass the result binary data to an image viewer implementation.
It cannot be done in MS Excel. You will need to implement your own viewer.
You won't be able to view an image inside of an XML file unless you write a dedicated application for it that knows about your particular requirement.
The reason is that XML is character-based, but images are not - they are binary data. A way to embed your image nevertheless is to transform it to something character-based first. For example, you could Base64-encode your image first and embed the resulting string in your XML. But I suppose there is no way to tell Excel to interpret this data as an image right away.
Because embedding binary files into XML using Base64 is such a common idiom, XML Schema even has its own data type for this: base64Binary.
精彩评论