in reply to Data Exchange between perl and java.
This was OK until I started encountering some data which was outside the 7bit ascii range that was not escaped and throwing some XML parsing tools. I extended the code to do a general escape of characters outside the 7bit range.
You could use a similar approach if you find that unescaped chars are causing a problem.
sub XML::Writer::_escapeLiteral { # escape 'normal' characters e.g. ampersand if ($_[0] =~ /[<>&"']/) { $_[0] =~ s/\&/&/g; # ampersand $_[0] =~ s/\"/"/g; # quotes $_[0] =~ s/\</</g; # left angle $_[0] =~ s/\>/>/g; # right angle $_[0] =~ s/\'/'/g; # apostrophe # Add more here... } # Look for occurrances of chars in the range outside normal 7 bit +ascii table # Note the character in Octal if ($_[0] =~ /([\177-\377])/) { my $escapedString = ""; # Generic escape for all other chars while ($_[0] =~ /\G(.*?)([\177-\377])/gc) { # concat the escaped char in the form { $escapedString .= sprintf ("%s&#%d;", $1, ord($2)); #print "escapedstring = $1 \n"; } # Concat whatever is left if ($_[0] =~ /\G(.*)$/g) { $escapedString .= $1; } return $escapedString; } return $_[0]; }
Enjoy!
Inman
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Data Exchange between perl and java.
by GermanHerman (Sexton) on Aug 15, 2003 at 22:13 UTC |