Quote(3pm)
π Quote(3pm) β XML::Quote π
okay bestie sit DOWN because today we're talking about XML::Quote, straight out of the User Contributed Perl Documentation collection, and it is literally the most slay little module for making your strings XML-safe. no cap.
β¨ NAME β¨
XML::Quote β XML quote/dequote functions π
πΈ SYNOPSIS πΈ
use strict;
use XML::Quote qw(:all);
my $str=q{666 > 444 & "apple" < 'earth'};
print xml_quote($str),"\n";
# 666 > 444 & "apple" < 'earth'
my $str2=q{666 > 444 & "apple" < 'earth'};
print xml_dequote($str2),"\n";
# 666 > 444 & "apple" < 'earth'
my $str3=q{666 > 444 & "apple" < 'earth'};
print xml_quote_min($str3),"\n";
# 666 > 444 & "apple" < 'earth'
likeβ¦ look at her go. three functions, three little glow-ups. π
π¦ DESCRIPTION π¦
so basically this module hands you functions that quote and dequote strings the "xml" way. that's it, that's the vibe. β¨
and here's the part where it gets iconic: every single one of these functions is written in XS and they are very fast. they correctly process utf8, tied, overloaded variables and all the rest of that perl "magic". she handles it. she always handles it. π
π FUNCTIONS π
$quoted = xml_quote($str);β this one replaces all occurences of the symbols'&','"',''','>','<'into'&','"',''','>','<'respectively. β¨
it returns the quoted string, or undef if $str is undef. no drama, no surprises.
$dequoted = xml_dequote($str);β the reverse queen π«Ά she replaces all occurences of'&','"',''','>','<'into'&','"',''','>','<'respectively. and every other entity (for example ) will not be touched. she minds her business. π
returns the dequoted string, or undef if $str is undef.
$quoted = xml_quote_min($str);β the "minimal effort, maximum results" version π she replaces all occurences of the symbols'&','"','<'into'&','"','<'respectively. the symbols'''and'>'are not replaced. not her problem, not her business.
returns the quoted string, or undef if $str is undef.
π EXPORT π
xml_quote(), xml_dequote() are exported as default. yes bestie, they just show up. no asking required. π
π₯ PERFORMANCE π₯
you can use t/benchmark.pl to test the perfomance. here's the result on my P4 box β and ngl, the receipts are devastating for the pure-perl girlies π
Benchmark: timing 1000000 iterations of perl quote, xs quote...
perl quote: 108 wallclock secs (88.08 usr + 0.01 sys = 88.09 CPU) @ 11351.64/s (n=1000000)
xs quote: 20 wallclock secs (16.78 usr + 0.00 sys = 16.78 CPU) @ 59591.20/s (n=1000000)
Benchmark: timing 1000000 iterations of perl dequote, xs dequote...
perl dequote: 106 wallclock secs (85.22 usr + 0.09 sys = 85.31 CPU) @ 11721.54/s (n=1000000)
xs dequote: 19 wallclock secs (15.92 usr + 0.02 sys = 15.94 CPU) @ 62743.13/s (n=1000000)
mental note bestie: it says perfomance in the original. i'm not fixing it. the typo has lore now. π
π 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. π«Ά
and that's the whole page, bestie β this doc shipped as part of perl v5.42.3, dated 2026-08-19. quote your strings, dequote your strings, stay iconic. periodt. πβ¨ππ¦πΈπ
π¦ where this page comes from
- ubuntu stonking: libxml-quote-perl 1.02-5build6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms