Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: binary data in XML

by sgt (Deacon)
on Feb 29, 2008 at 00:08 UTC ( [id://671058]=note: print w/replies, xml ) Need Help??


in reply to binary data in XML

CDATA sections originate from a related SGML concept and are used for verbatim text (like code).

They are simply a way to stop any special entity-like processing and are certainly *not* meant for binary data. They are many schemes for binary XML.

If the document is valid UTF-8, then base64-enc of values is useful and does not need escaping as quotes are not part of the image set. Obviously you could also use directly the encoding data in a CDATA section but it seems less useful than:

<data local_enc="base64"> <value>c3RlcGhhbgo=</value> </data>
The whole arsenal of MIME/PEM conversions can be used. But be careful, there is one pitfall: the scheme *breaks* if the xml document uses an (at least 2 bytes) encoding like UTF-16 as a base64 sequence of bytes is not valid UTF-16. The solution is to use an extra conversion like  iconv -f ISO-88859-1 -t UTF-16 and its inverse.

Finally one way to encode  ]]> would be to close the CDATA section after outputting ]] and then open another one starting with  >

cheers --stephan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://671058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-29 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found