aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML and BLOBs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML and BLOBs" Watch "XML and BLOBs" New topic
Author

XML and BLOBs

Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
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.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
You can encode the XML tags in binary to store the BLOB from database,
I mean you have to wrap the BLOB binary data into your XML tag... The idea is

<metadata>
... lots of XML metadata about size, names, dimensions, vectors, etc. ...
</metadata>
<BLOB>
... whopping big chunk of binary data representing IEEE doubles ...
</BLOB>

Hope it helps...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Speaking of encoding binary data in XML, which methods do folks here prefer?
Base64? Something more advanced (and compact)?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
jacob nikom
Greenhorn

Joined: Oct 01, 2001
Posts: 12
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
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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 "&amp;". Similarly, any Unicode character can be encoded into the XML file using this type of references.
Elliotte Rusty Harold
author
Ranch Hand

Joined: Feb 25, 2004
Posts: 91
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>
jacob nikom
Greenhorn

Joined: Oct 01, 2001
Posts: 12
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
jacob nikom
Greenhorn

Joined: Oct 01, 2001
Posts: 12
I found how to do it:
http://www.javaworld.com/javatips/jw-javatip117_p.html
Elliotte Rusty Harold
author
Ranch Hand

Joined: Feb 25, 2004
Posts: 91
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML and BLOBs
 
Similar Threads
storing image
EJBs, Webcontainer and *Images*...
How to serialize Images using XStream?
Uploading, saving and displaying images using servlets
How to store & retrieve a video file from database?