The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


XML::CanonicalizeXML - Perl extension for inclusive (1.0 and 1.1) and exclusive canonicalization of XML using libxml2


use XML::CanonicalizeXML;



canonicalize (xml, xpath, namespace, exclusive, with_comments)


xml is the xml string to be canonicalized

xpath is a string containing an xpath statement to the part of the xml document to be canonicalized, can optionally be null. See the examples provided with libxml2 for further details.

namespace is a string containing a list of namespaces to be included (only used in exclusive canonicalization)

exclusive is an int to specify exclusive canonicalization (1 = exclusive, 0 = non-exclusive, 2 = exclusive v1.1)

with_comments is an int specifying whether comments are included in the canonicalized xml (0 = comments not included)

the function returns a string containing the canonicalized xml.


None by default.

SEE ALSO for GitHub project for full details of libxml2


Stefan Zasada, <> with thanks to Mark Mc Keown


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.