#!/usr/bin/perl -w use strict; use MIME::Base64; local $/; my $xml=<>; $xml =~ s/\b\s*\n\s*\b//gs; $xml =~ s/(.*?)<\/key>\s*\n\s*/squote(unescape($1))."=>"/ges; $xml =~ s/(.*?)<\/string>/dquote(unescape($1)).","/ge; $xml =~ s/(.*?)<\/integer>/$1,/g; $xml =~ s/(.*?)<\/date>/date("$1"),/g; $xml =~ s/(.*?)<\/data>/sprintf("hex(\"%s\"),",unpack('H*',decode_base64($1)))/ge; $xml =~ s//{/g; $xml =~ s/<\/dict>/},/g; $xml =~ s//{},/g; $xml =~ s//[/g; $xml =~ s/<\/array>/],/g; $xml =~ s//[],/g; print $xml; sub squote { my $txt=shift; $txt =~ s/['\\]/\\$&/g; $txt =~ s/\n/\\n/g; $txt =~ s/\r/\\r/g; $txt =~ s/\t/\\t/g; $txt =~ s/\0/\\0/g; return ($txt =~ /^\w+$/) ? $txt : "'$txt'"; } sub dquote { my $txt=shift; $txt =~ s/["\\]/\\$&/g; $txt =~ s/\n/\\n/g; $txt =~ s/\r/\\r/g; $txt =~ s/\t/\\t/g; $txt =~ s/\0/\\0/g; return "\"$txt\""; } sub unescape { my $txt=shift; $txt=~s/<//g; $txt=~s/"/"/g; $txt=~s/&#(\d\w+);/chr(eval($1))/g; $txt=~s/&/&/g; return $txt; }