The prevalent
XML 1.0 spec forbids the use of most "control" characters (in the range #x00 - #x19), and that makes it a terrible format for shipping binary data. Even if your API requirement starts off as being printable text-only, you'd soon slam hard into this limitation once you demand more out of your XML use.
The workaround is to encode your binary data (e.g. Base64) into an XML-compatible string that you can embed in the XML. This introduces an extra decoding step when you want to get back at your binary data.
... add the seralized files to a hash, convert the hash to XML, print the XML to a socket, then, on the other end of the socket, convert the XML back to a perl hash and deseralize the files.
Consider that what you want is to get that Perl hash safely across. Why not just ship binary data across using
Storable?
use Data::Dumper;
use Storable qw(nfreeze thaw);
my $request = { TYPE => 'UPLOAD', DATA => { file1 => 'content1', file2
+ => 'content2' } };
my $serialized = nfreeze $request; # send this binary string
my $deserialized = thaw $serialized; # round trip!
print Dumper $deserialized;
Or use a format like
JSON? See
JSON::XS.
If all you care about is to ship the files across, then consider using
Archive::Tar with compression as a way of packaging the files. The tar object can read/write from filehandles and would work with sockets.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.