XML::G...String(3pm)
π 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 π
perl(1)XML::Grove(3)- Extensible Markup Language (XML) <http://www.w3c.org/XML>
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
- debian bookworm: libxml-grove-perl 0.46alpha-14 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libxml-grove-perl 0.46alpha-14 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libxml-grove-perl 0.46alpha-14 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libxml-grove-perl 0.46alpha-14 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libxml-grove-perl 0.46alpha-14 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms