Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 799
  • Last Modified:

storing binary data in XML

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
BeeRoo
Asked:
BeeRoo
  • 2
2 Solutions
 
iamjhkangCommented:
Base64 MIME encoding will do.

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

HTH.
0
 
monasCommented:
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
 
monasCommented:
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
 
BigRatCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now