Hello Monks,

I am attempting to seralize several files (created by a Win32 program called Farm Works Site Mate), 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. Here's an example of what I have so far.

#!/usr/bin/perl -w use strict; use File::Slurp qw(read_file); use XML::Dumper qw(pl2xml); my @DIRECTORIES = ( ['01-09-2012','/home/user/test/01-09-2012'], ['01-11-2012','/home/user/test/01-11-2012'], ['12-13-2011','/home/user/test/12-13-2011'], ); my %DATES; for my $dir (@DIRECTORIES) { $DATES{$dir->[0]} = _slurp_directory($dir->[1]); } my $request = { TYPE => 'UPLOAD', DATA => \%DATES, }; my $xml = pl2xml($request); print $xml; exit 0; sub _slurp_directory { my $directory = shift; my %DIR; if (opendir my $dh, $directory) { my @files = readdir $dh; closedir $dh; for my $file (@files) { next if $file eq "." || $file eq ".."; $DIR{$file} = read_file "$directory/$file"; } } return \%DIR; }

This would work fine but not all of the files I am working with are ASCII. I get the following error when trying this with non-ASCII encoded files:

not well-formed (invalid token) at line 10, column 39, byte 813 at /usr/lib/perl5/XML/Parser.pm line 187

Here are some of the files:

79342 SH_Grid.smb
SMB1 ; CMD_SCOUT_OPENLOG "Z:\home\user\SiteMate\01-11-2012\79342 SH.fgp" ; CMD_SCOUT_OPENBK "Z:\home\user\SiteMate\01-11-2012\79342 SH_GridPt.shp +" WGS84 LATLON 101 CMD_SCOUT_OPENBK "Z:\home\user\SiteMate\01-11-2012\79342 SH_GridLn.shp +" WGS84 LATLON 101 ;
79342 SH.mid
SMB1 ; CMD_SCOUT_OPENLOG "Z:\home\user\SiteMate\01-11-2012\79342 SH.fgp" ; CMD_SCOUT_OPENBK "Z:\home\user\SiteMate\01-11-2012\79342 SH_GridPt.shp +" WGS84 LATLON 101 CMD_SCOUT_OPENBK "Z:\home\user\SiteMate\01-11-2012\79342 SH_GridLn.shp +" WGS84 LATLON 101 ;
79342 SH PNTS.mif
VERSION 300 CHARSET "WindowsLatin1" DELIMITER "," COORDSYS Earth Projection 1,104 COLUMNS 2 __SAMPLEID char(40) _ELEVATION float DATA POINT -89.38364924 41.11561035 POINT -89.38364294 41.11651634 POINT -89.38364006 41.11741473 POINT -89.38364654 41.11832219 POINT -89.38484210 41.11832490 POINT -89.38484192 41.11741636 POINT -89.38484605 41.11650997 POINT -89.38483886 41.11560669 POINT -89.38605241 41.11560940 POINT -89.38604611 41.11651268 POINT -89.38604899 41.11741690 POINT -89.38604683 41.11832382 POINT -89.38724527 41.11831962 POINT -89.38724041 41.11741744 POINT -89.38725120 41.11651485 POINT -89.38724706 41.11560452 POINT -89.38844640 41.11561306 POINT -89.38844964 41.11651431 POINT -89.38845665 41.11741798 POINT -89.38844712 41.11832056

There are several other file types (.fdt, .fpg, .gpe, .shp, .shx, and many more) but my text editor isn't able to recognize their encoding types. I could archive the files into a ZIP file, but I end up with the same error in that case. So, with that in mind...How can I seralize any file in a way that is compatible with XML?

Thanks,
-cory-


In reply to How can I seralize a file for use with XML? by Lamont85

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.