XML::G...String(3pm)

πŸ“¦
version 0.46alpha Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

XML::Grove::AsString β€” bestie, this is the one that turns your XML objects into a plain ol' string 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

use XML::Grove::AsString;

# Using as_string method on XML::Grove::Document or XML::Grove::Element:
$string = $xml_object->as_string OPTIONS;
$string = $element->attr_as_string $attr, OPTIONS;

# Using an XML::Grove::AsString instance:
$writer = new XML::Grove::AsString OPTIONS;

$string = $writer->as_string($xml_object);
$writer->as_string($xml_object, $file_handle);

πŸ‘‘ DESCRIPTION πŸ‘‘

okay so picture this: you call "as_string" on an XML object and it hands you back all the character data contents of that object as a string β€” and yes, that means every single element underneath it too, no skipping πŸ’…. And if you call "attr_as_string" on an element, you get the contents of whatever attribute you named, as a string. iconic.

Now the sad part 😭: comments, processing instructions, and (by default) entities all just return an empty string. it's giving "ghosted".

OPTIONS can be either a key-value list or a hash holding the options down below. oh and fun fact: OPTIONS can be modified directly in the object, so it's not a read-only situation, bestie. the defaults are no filtering and entities mapped to empty strings. periodt.


✨ OPTIONS ✨

  • Filter β€” "Filter" is an anonymous sub that gets called to process character data before it gets appended to the string that's being returned. super useful if you need to, like, escape characters that are special in your output format. it gets called like this:
$string = &$filter ($character_data);
  • EntityMap β€” "EntityMap" is either an object that accepts "lookup" methods, or an anonymous sub. it gets called with the entity replacement text (the data) and mapper options as arguments, and it returns the corresponding character replacements. here's how it's called if it's an object:
$replacement_text = $entity_map->lookup ($entity_data,
                                         $entity_map_options);

and here's how it's called if it's a sub:

$replacement_text = &$entity_map ($entity_data,
                                  $entity_map_options);
  • EntityMapOptions β€” "EntityMapOptions" is a hash that gets passed straight through to that "lookup" method or anonymous sub. what type of value it holds? that's defined by the entity mapping package or by the anonymous sub itself, so it's lowkey a "you do you" situation 🫢.
  • EntityMapFilter β€” "EntityMapFilter" is a flag that says whether mapped entities should get filtered after mapping. tiny flag, big job πŸ’….

🌈 EXAMPLES 🌈

here's an example of entity mapping using the Text::EntityMap module, slay:

use Text::EntityMap;
use XML::Grove::AsString;

$html_iso_dia = Text::EntityMap->load ('ISOdia.2html');
$html_iso_pub = Text::EntityMap->load ('ISOpub.2html');
$html_map = Text::EntityMap->group ($html_iso_dia,
                                    $html_iso_pub);

$element->as_string (EntityMap => $html_map);

πŸ’œ AUTHOR πŸ’œ

Ken MacLeod, ken@bitsko.slc.ut.us β€” king behavior, honestly πŸ‘‘


πŸŽ€ SEE ALSO πŸŽ€


and that's the whole page, bestie πŸ¦‹ this was perl v5.36.0, dated 2022-11-29, and it lives in the User Contributed Perl Documentation section β€” go forth and stringify responsibly, mwah πŸ’–
πŸ“¦ where this page comes from