• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

XML and BLOBs

 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Speaking of encoding binary data in XML, which methods do folks here prefer?
Base64? Something more advanced (and compact)?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
author
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
jacob nikom
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found how to do it:
http://www.javaworld.com/javatips/jw-javatip117_p.html
 
Elliotte Rusty Harold
author
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic