3 XML::LibXML::Common - Constants and Character Encoding Routines
9 use XML::LibXML::Common;
11 $encodedstring = encodeToUTF8( $name_of_encoding, $sting_to_encode );
12 $decodedstring = decodeFromUTF8($name_of_encoding, $string_to_decode );
16 XML::LibXML::Common defines constants for all node types and provides interface
17 to libxml2 charset conversion functions.
19 Since XML::LibXML use their own node type definitions, one may want to use
20 XML::LibXML::Common in its compatibility mode:
27 use XML::LibXML::Common qw(:libxml);
29 C<<<<<< :libxml >>>>>> tag will use the XML::LibXML Compatibility mode, which defines the old 'XML_'
30 node-type definitions.
34 use XML::LibXML::Common qw(:gdome);
36 C<<<<<< :gdome >>>>>> tag will use the XML::GDOME Compatibility mode, which defines the old 'GDOME_'
37 node-type definitions.
41 use XML::LibXML::Common qw(:w3c);
43 This uses the nodetype definition names as specified for DOM.
47 use XML::LibXML::Common qw(:encoding);
49 This tag can be used to export only the charset encoding functions of
55 By default the W3 definitions as defined in the DOM specifications and the
56 encoding functions are exported by XML::LibXML::Common.
59 =head2 Encoding functions
61 To encode or decode a string to or from UTF-8, XML::LibXML::Common exports two
62 functions, which provide an interface to the encoding support in C<<<<<< libxml2 >>>>>>. Which encodings are supported by these functions depends on how C<<<<<< libxml2 >>>>>> was compiled. UTF-16 is always supported and on most installations, ISO
63 encodings are supported as well.
65 This interface was useful for older versions of Perl. Since Perl >= 5.8
66 provides similar functions via the C<<<<<< Encode >>>>>> module, it is probably a good idea to use those instead.
72 $encodedstring = encodeToUTF8( $name_of_encoding, $sting_to_encode );
74 The function will convert a byte string from the specified encoding to an UTF-8
75 encoded character string.
80 $decodedstring = decodeFromUTF8($name_of_encoding, $string_to_decode );
82 This function converts an UTF-8 encoded character string to a specified
83 encoding. Note that the conversion can raise an error if the given string
84 contains characters that cannot be represented in the target encoding.
90 Both these functions report their errors on the standard error. If an error
91 occurs the function will croak(). To catch the error information it is required
92 to call the encoding function from within an eval block in order to prevent the
93 entire script from being stopped on encoding error.
96 =head2 A note on history
98 Before XML::LibXML 1.70, this class was available as a separate CPAN
99 distribution, intended to provide functionality shared between XML::LibXML,
100 XML::GDOME, and possibly other modules. Since there seems to be no progress in
101 this direction, we decided to merge XML::LibXML::Common 0.13 and XML::LibXML
102 1.70 to one CPAN distribution.
104 The merge also naturally eliminates a practical and urgent problem experienced
105 by many XML::LibXML users on certain platforms, namely mysterious misbehavior
106 of XML::LibXML occurring if the installed (often pre-packaged) version of
107 XML::LibXML::Common was compiled against an older version of libxml2 than
123 2001-2007, AxKit.com Ltd.
125 2002-2006, Christian Glahn.
127 2006-2009, Petr Pajas.
134 This program is free software; you can redistribute it and/or modify it under
135 the same terms as Perl itself.