NAME

XML::Quote - XML quote/dequote functions

SYNOPSIS

use XML::Quote;

my $str=q{666 > 444 & "apple" < 'earth'};
print xml_quote($str),"\n";
# 666 &gt; 444 &amp; &quot;apple&quot; &lt; &apos;earth&apos;

my $str2=q{666 &gt; 444 &amp; &quot;apple&quot; &lt; &apos;earth&apos;};
print xml_quote($str2),"\n";
# 666 > 444 & "apple" < 'earth'

DESCRIPTION

This module provides two functions to quote/dequote strings in "xml"-way.

All functions are written in XS and are very fast; they correctly process utf8, tied, overloaded variables and all the rest of perl "magic".

FUNCTIONS

$quoted = xml_quote($str);

This function replaces all occurences of symbols '&', '"', ''', '>', '<' to '&amp;', '&quot;', '&apos;', '&gt;', '&lt;' respectively.

Returns quoted string or undef if $str is undef.

$dequoted = xml_dequote($str);

This function replaces all occurences of '&amp;', '&quot;', '&apos;', '&gt;', '&lt;' to '&', '"', ''', '>', '<' respectively. All other entities (for example &nbsp;) will not be touched.

Returns dequoted string or undef if $str is undef.

EXPORT

xml_quote(), xml_dequote() are exported as default.

PERFORMANCE

You can use t/benchmark.pl to test the perfomance. Here is the result on my P4 box.

Benchmark: timing 1000000 iterations of perl quote, xs quote...
perl quote: 90 wallclock secs (81.16 usr +  0.01 sys = 81.17 CPU) @ 12319.82/s (n=1000000)
  xs quote: 17 wallclock secs (14.14 usr +  0.00 sys = 14.14 CPU) @ 70716.36/s (n=1000000)

AUTHOR

Sergey Skvortsov <skv@protey.ru>

SEE ALSO

http://www.w3.org/TR/REC-xml, perlre

COPYRIGHT

Copyright 2003 Sergey Skvortsov <skv@protey.ru>. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.