libxml and binary data

BlitzMax Forums/BlitzMax Programming/libxml and binary data

Jake L.(Posted 2008) [#1]
Hi,

just a quick question to all libxml users: what's the best way to store binary data in a node's content? Is there any buildin-functionality for it?

Thanks
Jake


Brucey(Posted 2008) [#2]
One way around it is to base64 encode the binary data, and then decode it on loading. Makes the data a bit bigger, but you might get away with compressing the xml too, if size is an issue (libxml supports de/compression of the document).


Jake L.(Posted 2008) [#3]
Thanks, I'll give it a try.


Difference(Posted 2008) [#4]
Ask yourself if you *really* need to do binary data in your xml file.
Can you link to the binary data as a file and have an xml tag/attribute point to it?

If it's because you want a "wad file" like solution, then look into zipping the xml together with the binary files.

As a last resort look into XML CDATA


Jake L.(Posted 2008) [#5]
I'd like to use a single file for exchanging parameters. All of them but a single image file are usual xml-tags. So I thought zipping them would be too much overhead and trouble for a single image that most of the time would be of small size.

If I Base64 encode my image, do I need to use CData or can I store it the usual way as a contentstring?


Difference(Posted 2008) [#6]
I think you'll be fine with just base64.

There is a base64 writer in libxml, but I don't know if it's avalable in Bruceys module.

http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterWriteBase64


Brucey(Posted 2008) [#7]
There is a base64 writer in libxml, but I don't know if it's avalable in Bruceys module.

Cool... I never noticed that there. I guess that would be rather useful ;-)


Brucey(Posted 2008) [#8]
I've knocked together a small Base64 module which might be handy for this job. Info here :

http://code.google.com/p/maxmods/wiki/Base64Module

And available in the Downloads section.


Jake L.(Posted 2008) [#9]
EXCELLENT! Just right in time. Thank you very very much!