Jump to content
  • Advertisement
Sign in to follow this  
Raeldor

Binary in XML?

This topic is 4514 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, I am working on a simple flashcard game for language learning and I would like to give the users the ability to create their own flashcards. This will mean giving them the ability to import sound and a picture from an external source. I would like to manage each deck of cards in one easy to use file and at the moment I am using XML but referencing the external files. Obviously this makes packaging the cards to be used by someone else very difficult. I would like to hold the card information AND the sound and picture all in the XML file instead of the filename. Is it possible to hold binary data in an XML file? Is this recommended? Would I need to write my own binary to ASCII convertor or such like (uuencode?), or does something already exist in standard XML to do this? Thanks! Rael

Share this post


Link to post
Share on other sites
Advertisement
I don't believe any standard exists for XML, but one method that has proven useful is to Base64 encode the data in the XML file.

Share this post


Link to post
Share on other sites
Quote:
Original post by daerid
I don't believe any standard exists for XML, but one method that has proven useful is to Base64 encode the data in the XML file.

Interesting, I'll have a Wiki on it. Thanks for the info!

Share this post


Link to post
Share on other sites
An alternative to Base64 encoding is ASCII85 encoding, which is slightly more compact and possibly easier to encode/decode.

Size Increase:
Ascii85 - 125%
base-64 - 133%

You'll need to create your own encoder or use a pre-existing one. At the point, it may actually be easier to come up with a binary format for your data file and write a simple GUI tool to allow users to edit their decks.

Share this post


Link to post
Share on other sites
about half way down the page http://www.w3schools.com/xml/xml_cdata.asp, it describes the CDATA element (which prevents your XML parser from trying to interpret your binary/hex/base64 data).

Share this post


Link to post
Share on other sites
Quote:
Original post by krez
about half way down the page http://www.w3schools.com/xml/xml_cdata.asp, it describes the CDATA element (which prevents your XML parser from trying to interpret your binary/hex/base64 data).


Unfortunately, CDATA sections are not the magic bullet they appear to be. The problem is that, although the contents of the CDATA section are ignored, it is not skipped over entirely because the parser must still watch for the ending CDATA tag "]]>". This, of course, means that you must be able to guarantee that your data will never contain those characters in that particular sequence, sure the odds are low and you can take your chances, but at some point in the future you can bet that your application will fail innexplicably due to this very problem. CDATA sections also cannot contain space or newline characters.

Even if you attempted to fix this problem by embedding escape sequences within the Binary data (which would still never provide you a guarantee) the parsing which would be required as a result would be much slower than base64 or Ascii85 to decode (I'd estimate 20 times slower at a minimum.)

As for XMP, that seems not to fit the bill since its embedding metadata to a single binary file, while the OP is looking to embed multiple binary data files into an XML file (which is essentially text-based metadata in this case.)

I've been looking into embedding binary data into XML myself and base64 or Ascii 85 are the best options in my oppinion.

Share this post


Link to post
Share on other sites
http://www.w3.org/XML/Binary/
or
http://www.matroska.org/
Quote:
It was derived from a project called MCF, but differentiates from it significantly because it is based on EBML (Extensible Binary Meta Language), a binary derivative of XML.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!