1XML::LibXML::Common(3)User Contributed Perl DocumentationXML::LibXML::Common(3)
2
3
4
6 XML::LibXML::Common - Constants and Character Encoding Routines
7
9 use XML::LibXML::Common;
10
11 $encodedstring = encodeToUTF8( $name_of_encoding, $sting_to_encode );
12 $decodedstring = decodeFromUTF8($name_of_encoding, $string_to_decode );
13
15 XML::LibXML::Common defines constants for all node types and provides
16 interface to libxml2 charset conversion functions.
17
18 Since XML::LibXML use their own node type definitions, one may want to
19 use XML::LibXML::Common in its compatibility mode:
20
21 Exporter TAGS
22 use XML::LibXML::Common qw(:libxml);
23
24 ":libxml" tag will use the XML::LibXML Compatibility mode, which
25 defines the old 'XML_' node-type definitions.
26
27 use XML::LibXML::Common qw(:gdome);
28
29 ":gdome" tag will use the XML::GDOME Compatibility mode, which defines
30 the old 'GDOME_' node-type definitions.
31
32 use XML::LibXML::Common qw(:w3c);
33
34 This uses the nodetype definition names as specified for DOM.
35
36 use XML::LibXML::Common qw(:encoding);
37
38 This tag can be used to export only the charset encoding functions of
39 XML::LibXML::Common.
40
41 Exports
42 By default the W3 definitions as defined in the DOM specifications and
43 the encoding functions are exported by XML::LibXML::Common.
44
45 Encoding functions
46 To encode or decode a string to or from UTF-8, XML::LibXML::Common
47 exports two functions, which provide an interface to the encoding
48 support in "libxml2". Which encodings are supported by these functions
49 depends on how "libxml2" was compiled. UTF-16 is always supported and
50 on most installations, ISO encodings are supported as well.
51
52 This interface was useful for older versions of Perl. Since Perl >= 5.8
53 provides similar functions via the "Encode" module, it is probably a
54 good idea to use those instead.
55
56 encodeToUTF8
57 $encodedstring = encodeToUTF8( $name_of_encoding, $sting_to_encode );
58
59 The function will convert a byte string from the specified encoding
60 to an UTF-8 encoded character string.
61
62 decodeToUTF8
63 $decodedstring = decodeFromUTF8($name_of_encoding, $string_to_decode );
64
65 This function converts an UTF-8 encoded character string to a
66 specified encoding. Note that the conversion can raise an error if
67 the given string contains characters that cannot be represented in
68 the target encoding.
69
70 Both these functions report their errors on the standard error. If an
71 error occurs the function will croak(). To catch the error information
72 it is required to call the encoding function from within an eval block
73 in order to prevent the entire script from being stopped on encoding
74 error.
75
76 A note on history
77 Before XML::LibXML 1.70, this class was available as a separate CPAN
78 distribution, intended to provide functionality shared between
79 XML::LibXML, XML::GDOME, and possibly other modules. Since there seems
80 to be no progress in this direction, we decided to merge
81 XML::LibXML::Common 0.13 and XML::LibXML 1.70 to one CPAN distribution.
82
83 The merge also naturally eliminates a practical and urgent problem
84 experienced by many XML::LibXML users on certain platforms, namely
85 mysterious misbehavior of XML::LibXML occurring if the installed (often
86 pre-packaged) version of XML::LibXML::Common was compiled against an
87 older version of libxml2 than XML::LibXML.
88
90 Matt Sergeant, Christian Glahn, Petr Pajas
91
93 2.0201
94
96 2001-2007, AxKit.com Ltd.
97
98 2002-2006, Christian Glahn.
99
100 2006-2009, Petr Pajas.
101
103 This program is free software; you can redistribute it and/or modify it
104 under the same terms as Perl itself.
105
106
107
108perl v5.30.0 2019-07-26 XML::LibXML::Common(3)