Solved

storing binary data in XML

Posted on 2002-07-19
7
774 Views
Last Modified: 2012-06-27
I'm curious about how I can store binary data in XML.
I know the CDATA functionality is often used to handle this, but, in my case, I can't be assured that the ]]> sequence will not be cointained in the data, causing all data after the ]]> character sequence to be lost. How can I get around this problem.
0
Comment
Question by:BeeRoo
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
iamjhkang earned 25 total points
ID: 7166286
Base64 MIME encoding will do.

Visit the site below.
http://www.vbxml.com/xml/articles/binary/Default.asp

HTH.
0
 
LVL 3

Assisted Solution

by:monas
monas earned 25 total points
ID: 7167007
If your binary will have few ]]> sequences then you could split it into several CDATA elements on this text. for example "binary" "abcd]]>efgh" could be written:

<![CDATA[abcd]]]]><![CDATA[>efgh]]>

Yes, you have to go through all the binary when you put it into xml, and it have 12 bytes/sequence overhead but on most binaries this should give better result than guaranteed 30+% overhead of Base64.
0
 
LVL 3

Expert Comment

by:monas
ID: 7167011
Hmmm, what will happen if your binary will have sequences that are not present in UTF-8 - I don't know. Maybe someone could comment?
0
 
LVL 27

Expert Comment

by:BigRat
ID: 7169130
Strictly speaking inside a CDATA sequence the byte encoding should not matter. I prefer however the base64 encoding. In my RatScript I have implemented zlib to compress strings and base64 to encode them. Consequently storing binary data in XML is no problem - compress and base64 the result!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# XDocument.Save adds unwanted encoding information 5 51
Path of Workbook 3 78
JQuery to parse xml string and get element by id 4 35
.net and XML report from SCCM 5 25
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question