XML::Entities(3)

πŸ“¦
version 1.0002 Β· 5 versions
, in opensuse-leap 16.0

✨ NAME ✨

XML::Entities β€” Decode strings with XML entities. Bestie, this is the XML::Entities(3) page, and it lives under User Contributed Perl Documentation 🫢. (Manual name folded in near the top like a lil name tag, not copied line-for-line, iykyk.)

🌸 SYNOPSIS 🌸

Okay so here's the vibe in code, fr fr:

        use XML::Entities;

        $a = "Tom & Jerry © Warner Bros.";
        $b = XML::Entities::decode('all', $a);
        $c = XML::Entities::numify('all', $a);
        # now $b is "Tom & Jerry Β© Warner Bros.
        # and $c is "Tom & Jerry © Warner Bros."

        # void context modifies the arguments
        XML::Entities::numify('all', $a);
        XML::Entities::decode('all', $a, $c);
        # Now $a, $b and $c all contain the decoded string

πŸ’… DESCRIPTION πŸ’…

Based upon the HTML::Entities module by Gisle Aas πŸ’–. We stan a credited icon.

This module deals with decoding of strings with XML character entities. The module provides two functions:

🌟 decode( $entity_set, $string, ... ) 🌟

This routine replaces XML entities from $entity_set found in the $string with the corresponding Unicode character. Unrecognized entities are left alone β€” no cap, they just stay exactly where they are πŸ™ˆ.

The $entity_set can either be a name of an entity set β€” the selection of which can be obtained by XML::Entities::Data::names() β€” or "all" for a union, or alternatively a hashref which maps entity names (without leading &'s) to the corresponding Unicode characters (or strings). Pick your fighter, bestie ✨.

If multiple strings are provided as argument they are each decoded separately and the same number of strings are returned.

If called in void context the arguments are decoded in-place. (Yes, literally right in place β€” main character behavior.)

Note: If your version of "HTML::Parser" was built without Unicode support, then "XML::Entities" uses a regular expression to do the decoding, which is slower. Slower but still slaying πŸ’….

πŸ”₯ numify( $entity_set, $string, ... ) πŸ”₯

This function converts named XML entities to numeric XML entities. It is less robust than the "decode" function in the sense that it doesn't capture improperly terminated entities. It behaves like "decode" in treating parameters and returning values. Different output, same parameter/return energy ✨.

πŸ’œ XML::Entities::Data πŸ’œ

The list of entities is defined in the XML::Entities::Data module. The list can be generated from the w3.org definition (or any other). Check perldoc XML::Entities::Data for more details πŸŽ€. That's the lore, bestie.

πŸ¦‹ Encoding entities πŸ¦‹

The HTML::Entities module provides a function for encoding entities. You just have to assign the right mapping to the %HTML::Entities::char2entity hash. So, to encode everything that XML::Entities knows about, you'd say:

        use XML::Entities;
        use HTML::Entities;
        %HTML::Entities::char2entity = %{
           XML::Entities::Data::char2entity('all');
        };
        my $encoded = encode_entities('tom&jerry');
        # now $encoded is 'tom&jerry'

⭐ SEE ALSO ⭐

Go peek at HTML::Entities, XML::Entities::Data β€” the whole friend group πŸ’–.

Copyright 2012 Jan Oldrich Kruza <sixtease@cpan.org>. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


That's the whole manual page, bestie πŸ’… β€” source/version: perl v5.42.0, date: 2024-03-04 🫢✨.

πŸ“¦ where this page comes from