1XML::Entities(3) User Contributed Perl Documentation XML::Entities(3)
2
3
4
6 XML::Entities - Decode strings with XML entities
7
9 use XML::Entities;
10
11 $a = "Tom & Jerry © Warner Bros.";
12 $b = XML::Entities::decode('all', $a);
13 $c = XML::Entities::numify('all', $a);
14 # now $b is "Tom & Jerry © Warner Bros.
15 # and $c is "Tom & Jerry © Warner Bros."
16
17 # void context modifies the arguments
18 XML::Entities::numify('all', $a);
19 XML::Entities::decode('all', $a, $c);
20 # Now $a, $b and $c all contain the decoded string
21
23 Based upon the HTML::Entities module by Gisle Aas
24
25 This module deals with decoding of strings with XML character entities.
26 The module provides two functions:
27
28 decode( $entity_set, $string, ... )
29 This routine replaces XML entities from $entity_set found in the
30 $string with the corresponding Unicode character. Unrecognized
31 entities are left alone.
32
33 The $entity_set can either be a name of an entity set - the
34 selection of which can be obtained by XML::Entities::Data::names(),
35 or "all" for a union, or alternatively a hashref which maps entity
36 names (without leading &'s) to the corresponding Unicode characters
37 (or strings).
38
39 If multiple strings are provided as argument they are each decoded
40 separately and the same number of strings are returned.
41
42 If called in void context the arguments are decoded in-place.
43
44 Note: If your version of "HTML::Parser" was built without Unicode
45 support, then "XML::Entities" uses a regular expression to do the
46 decoding, which is slower.
47
48 numify( $entity_set, $string, ... )
49 This functions converts named XML entities to numeric XML entities.
50 It is less robust than the "decode" function in the sense that it
51 doesn't capture improperly terminated entities. It behaves like
52 "decode" in treating parameters and returning values.
53
54 XML::Entities::Data
55 The list of entities is defined in the XML::Entities::Data module. The
56 list can be generated from the w3.org definition (or any other). Check
57 "perldoc XML::Entities::Data" for more details.
58
59 Encoding entities
60 The HTML::Entities module provides a function for encoding entities.
61 You just have to assign the right mapping to the
62 %HTML::Entities::char2entity hash. So, to encode everything that
63 XML::Entities knows about, you'd say:
64
65 use XML::Entities;
66 use HTML::Entities;
67 %HTML::Entities::char2entity = %{
68 XML::Entities::Data::char2entity('all');
69 };
70 my $encoded = encode_entities('tom&jerry');
71 # now $encoded is 'tom&jerry'
72
74 HTML::Entities, XML::Entities::Data
75
77 Copyright 2012 Jan Oldrich Kruza <sixtease@cpan.org>. All rights
78 reserved.
79
80 This library is free software; you can redistribute it and/or modify it
81 under the same terms as Perl itself.
82
83
84
85perl v5.30.1 2020-01-30 XML::Entities(3)