The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Image data in XML?

I'm writing a graphics layout application in Delphi 6. The app provides for drawing basic shapes and text, as well as importing bitmaps and metafile images. The layouts are saved in XML format. The basic shape attributes are described, and image content is also included. Since there could be multiple images in a layout, the file can potentially get pretty big. When a layout is loaded, everything is parsed and appropriate objects are created.

Is this the 'right' way to do this...for images, I mean? I thought about saving only the path to separate image files, but that would mean having multiple files for a single layout, something I'd like to avoid.

Has anyone else done something similar?
Dave Keezer Send private email
Thursday, May 05, 2005
"Some people, when confronted with a problem, think 'I know, I'll use XML.' Now they have two problems."


Are the users expecting a single file to encapsulate the document along with the images?  If the user copies the xml file somewhere else it should bring the images along (embedded data) automatically.

The flip side is users breaking all the external links to images on every copy or having to educate the users on copying external images.
lumberjack Send private email
Thursday, May 05, 2005
You might want to peruse some of the documents on XML by Adobe.

Also, one may wish to ponder the xml schema used by visio
Thursday, May 05, 2005
There are two 'right' ways to do it:
1. Links to external files (as you mentioned).
2. Base-64 encoding the images and storing them in the XML.

#1 has the obvious disadvantages that have already been mentioning.  #2 has the disadvantages that the data size is increased, the readability of the XML is decreased, and extracting the images from the XML can be annoying for the user. 

A best-of-both-worlds solution that I've seen is to keep the XML file and the images together in a zip file and use that as your format. 

Those links to Adobe and Microsoft look interesting.  I'm definitely going to check those out to see how they've approached the problem.
SomeBody Send private email
Thursday, May 05, 2005
Maybe take a look at the MTOM spec?

"SOAP Message Transfer Optimization Mechanism"

It's XML with binary encoding and attachments. Hasn't got a whole lot of uptake yet but it seems to fit with what you need.
Chris Tavares Send private email
Friday, May 06, 2005
I'm going to assume that you've already seen SVG ( ), which is a W3C standard for two dimendional vector graphics in XML. Given that, you could look at what Adobe Illustrator does when the user saves as SVG. I'm not positive, but I think they do base64 encoding of included raster images. Have a look and see if it gives you any ideas.
Rob Send private email
Friday, May 06, 2005
Thanks to everyone who provided tips and links. I plan to do more research based on your input. BTW, I currently use Base-64 encoding for the image data.
Dave Keezer Send private email
Friday, May 06, 2005
Well, there might be a third solution to the problem as well.

Create an archive file from within your application. This archive file should be implemented as a zip file, containing the XML and the images. Now use your favorite ZIP-handling library to read/write the XML or the images. Your xml will still parse quickly, and you won't have to worry about your users moving/deleting their images.
BenjiSmith Send private email
Friday, May 06, 2005
My approach to this in Surfulater is to store images in a separate simple embedded database and reference these from the XML file. This means you have two files instead of an ideal one, but everything is nicely packaged up.

This works well and I can load up the XML very, very quickly without having to first extract it from a ZIP file as others have suggested. If performance isn't an issue packing everything into a zip maybe a reasonable approach.

Another alternative is Base64 encoding the images in the xml file, but I don't much like that because the xml file will get a lot bigger, and because of the extra overhead in encoding/decoding etc.
Neville Franks Send private email
Friday, May 06, 2005
If your images are BMP or anything not already in somewhat compressed format like JPG, then gzip them before doing Base64. Keep them in your XML document so you don't have to worry about whether they are accessible. Good luck.
Ben Bryant
Saturday, May 07, 2005
The correct XML way to do this is something like:

<Image name="MyImage" encoding="png">

Obviously there's more too it: you'll need to worry about namespaces and such. But that's the basic idea.
Tuesday, May 10, 2005
Caveat - That is soooooo wrong in this case it's not even funny.

Since it's base64 you can represent the data as just another element.
Tuesday, May 10, 2005
"The correct XML way to do this is something like:

<Image name="MyImage" encoding="png">

I hope your sarcasm bit was on because this was the funniest JOS post I have ever read.
Johnny W. Appleseed
Tuesday, May 10, 2005
If you're running exclusively on NTFS (i.e. Windows), *perhaps* you could use alternate file streams to store the binary blobs?

In other words, the main XML file is text-only, but the attached streams carry the binary data. You can have any number of streams.

Of course that wouldn't be 100% XML, but efficient. You'd have one file, with all the image data built in, with none of the base64 loss.


<Image name="MyImage" encoding="png" location="stream12" length="98797">
Alex Send private email
Wednesday, May 11, 2005
I agree with Benji above...for one file portability write the data into a zip file with an xml file and multiple image files in the zip file.  For xml, bmp and ico you will also gain some copression. 

For extra points don't use a .zip extension -- would want the user to muck about would we -- and your code should not care if the file is or settings or
O Canader
Friday, May 13, 2005

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz