.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Quote 3pm" .TH Quote 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME XML::Quote \- XML quote/dequote functions .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use strict; \& use XML::Quote qw(:all); \& \& my $str=q{666 > 444 & "apple" < \*(Aqearth\*(Aq}; \& print xml_quote($str),"\en"; \& # 666 > 444 & "apple" < 'earth' \& \& my $str2=q{666 > 444 & "apple" < 'earth'}; \& print xml_dequote($str2),"\en"; \& # 666 > 444 & "apple" < \*(Aqearth\*(Aq \& \& my $str3=q{666 > 444 & "apple" < \*(Aqearth\*(Aq}; \& print xml_quote_min($str3),"\en"; \& # 666 > 444 & "apple" < \*(Aqearth\*(Aq .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module provides functions to quote/dequote strings in "xml"\-way. .PP All functions are written in XS and are very fast; they correctly process utf8, tied, overloaded variables and all the rest of perl "magic". .SH FUNCTIONS .IX Header "FUNCTIONS" .ie n .IP "$quoted = xml_quote($str);" 4 .el .IP "\f(CW$quoted\fR = xml_quote($str);" 4 .IX Item "$quoted = xml_quote($str);" This function replaces all occurences of symbols '&', '"', ''', '>', '<' to '&', '"', ''', '>', '<' respectively. .Sp Returns quoted string or undef if \f(CW$str\fR is undef. .ie n .IP "$dequoted = xml_dequote($str);" 4 .el .IP "\f(CW$dequoted\fR = xml_dequote($str);" 4 .IX Item "$dequoted = xml_dequote($str);" This function replaces all occurences of '&', '"', ''', '>', \&'<' to '&', '"', ''', '>', '<' respectively. All other entities (for example  ) will not be touched. .Sp Returns dequoted string or undef if \f(CW$str\fR is undef. .ie n .IP "$quoted = xml_quote_min($str);" 4 .el .IP "\f(CW$quoted\fR = xml_quote_min($str);" 4 .IX Item "$quoted = xml_quote_min($str);" This function replaces all occurences of symbols '&', '"', '<' to '&', '"', '<' respectively. Symbols ''' and '>' are not replaced. .Sp Returns quoted string or undef if \f(CW$str\fR is undef. .SH EXPORT .IX Header "EXPORT" \&\fBxml_quote()\fR, \fBxml_dequote()\fR are exported as default. .SH PERFORMANCE .IX Header "PERFORMANCE" You can use t/benchmark.pl to test the perfomance. Here is the result on my P4 box. .PP .Vb 3 \& 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) .Ve .SH AUTHOR .IX Header "AUTHOR" Sergey Skvortsov .SH "SEE ALSO" .IX Header "SEE ALSO" , perlre .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2003 Sergey Skvortsov . All rights reserved. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.