This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi guys, I have to display images from server and am planning to use xml for the data transfer. I have images in my database in the form of a BLOBs. I am not sure how to get those BLOBs into XML. How does XML handle images? I have seen many references where XML contains the path of the image on the server. But what if the images are stored in BLOBs? Can I put the whole BLOB into an XML tag? Thanks.
Sorry Ko Ko Naing, but I did not get it. You suggested: <metadata> ... lots of XML metadata about size, names, dimensions, vectors, etc. ... </metadata> <BLOB> ... whopping big chunk of binary data representing IEEE doubles ... </BLOB> What do you mean by the "whopping big chunk of binary data"? Is it a string of charachters? Is it at array of integers representing each byte in the binary data? How you can represent in XML something which is not ASCII character? Jacob Nikom
Joined: Jan 23, 2002
Originally posted by jacob nikom: How you can represent in XML something which is not ASCII character?
By encoding it. For example, the ampersand is an illegal character to have inside an element so you encode it as "&". Similarly, any Unicode character can be encoded into the XML file using this type of references.
Item 19 of Effective XML suggests using base 64 for this purpose. You can't embed raw binary data in XML but once it's Base-64 encoded it's not a problem. I would, however, serioulsy conisder whether this is what you really want to do. Data digitized from analog sources such as photographs, audio, and video is the major use case for which XML is inappropriate. Is it possible to transmit the imahes separately from the XML that describes them? Or bundle them together in a Zip archive or a MIME multipart message? If bandwidth and CPU speed are not of particular concern to you, Base 64 may work, but it's rarely ideal.
Elliotte Rusty Harold<br />Author of <a href="http://cafe.elharo.com/web/refactoring-html/" target="_blank" rel="nofollow">Refactoring HTML</a>
Joined: Oct 01, 2001
The problem is that this representation is VERY inefficient. Yes, you can represent each byte as three digits, but you are triple the size of your data! You can represent each byte by adding ampersand in front of it and using some other symbols, but it is VERY inefficient as well! In case of binary data(images) as a rule you have a lot of binary data and very few tags. So in order to insert few tags to be able to do XML parsing, you have to triple the size of your data! I think that is what is called "If you have a hammer everything looks like a nail". Jacob Nikom
Huffman encoding! Cute. I hadn't seen that before but it makes sense. I suspect, though, that the performance would be improved (and the code be made a lot simpler) by compressing the binary data with a GzipOutputStream and Base-64 encoding the result, rather than trying to write your own compression code. I also don't think eny compression would have much success with pre-compressed data like JPEGs, MPEGS, or MP3s.