File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes storing attachment files in xml / reading from xml 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 "storing attachment files in xml / reading from xml" Watch "storing attachment files in xml / reading from xml" New topic

storing attachment files in xml / reading from xml

Fon Drank

Joined: Feb 20, 2007
Posts: 14
Is there a standard way of saving "attachment files" in xml? I have looked and it seems like most people recommend base64 encoding binary data.

So can someone critique my workflow thoughts for attaching files and retrieving them later on from xml?

attach files workflow:
1) user selects the file to attach
2) store the file in memory as a byte stream
3) use some kind of API to base64 encode the byte stream into a String
4) write out the string to xml

retrive file and display workflow:
1) retrieve the String from xml
2) convert to a byte stream using base64 decoding API
3) write out the byte stream to a temp file
4) call high level API to open the file using whatever program the OS associates with the file extension

Any help is appreciated! Also, is there a standardized tagging convention for storing attachments in xml?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Well, look at it this way. XML is a format designed for storing textual data. And most of those attachments (you didn't say what you planned to attach them to) are not in any way text. So XML isn't really the first format I would choose for storing that data. I would just store the data as is without modifying it in any way, I don't see any point in wrapping it in XML.
I agree. Here's the link:
subject: storing attachment files in xml / reading from xml
It's not a secret anymore!