XML::P...e::Tree(3pm)
π NAME π
okay so bestie, gather round: XML::Parser::Lite::Tree β it's a Lightweight XML tree builder β¨ (yes that's literally the whole name section, it's giving minimalism and honestly? iconic)
This is from the User Contributed Perl Documentation for XML::P...e::Tree(3pm), and no I will not be normal about it π
β¨ SYNOPSIS β¨
the vibes, in code form:
use XML::Parser::Lite::Tree;
my $tree_parser = XML::Parser::Lite::Tree::instance();
my $tree = $tree_parser->parse($xml_data);
OR
my $tree = XML::Parser::Lite::Tree::instance()->parse($xml_data);
so basically you can grab the parser, keep it in a variable, and call parse on it β OR you can be extra and chain it all in one line like the main character you are π
both slay, pick your fave π«Ά
πΈ DESCRIPTION πΈ
okay so here's the tea β β this is a singleton class for parsing XML into a tree structure. one class, one instance, very exclusive, very VIP π§
and you're probably like "bestie, how is this different from every other XML tree generator out there?" and I'm SO glad you asked π it uses XML::Parser::Lite, which is a pure perl XML parser. meaning: with this module you can tree-ify simple XML without having to compile any C. no C compiler, no build drama, no crying in the terminal π periodt.
for example, this XML right here:
<foo woo="yay"><bar a="b" c="d" />hoopla</foo>
parses into this tree:
{
'children' => [
{
'children' => [
{
'children' => [],
'attributes' => {
'a' => 'b',
'c' => 'd'
},
'type' => 'element',
'name' => 'bar'
},
{
'content' => 'hoopla',
'type' => 'text'
}
],
'attributes' => {
'woo' => 'yay'
},
'type' => 'element',
'name' => 'foo'
}
],
'type' => 'root'
};
look at that nesting, it's giving π² tree structure, it's giving data, it's giving ate π
so every node has a "type" key, and it's one of three things: "root", "element", or "text" β
"root"β that's the document root, and the only thing it carries is an array ref calledchildrenπ"element"β that's your normal tag bestie, and it holds an array refchildren, a hash refattributes, and a stringnameπ"text"β these cuties contain literally just acontentstring, nothing else, no notes π¦
π METHODS π
"instance()"β hands you back an instance of the tree parser. that's it. that's the method. simple, clean, iconic β¨"new( options... )"β makes you a brand new parser. valid options include"process_ns", which is the one that processes namespaces π"parse($xml)"β takes the xml sitting in$xml, parses it, and returns the tree as a hash ref π«Ά
π AUTHOR π
Copyright (C) 2004-2008, Cal Henderson, <cal@iamcal.com>
shoutout to Cal, the original author, we love and respect the legacy π
π₯ SEE ALSO π₯
XML::Parser::Lite.
like, go read that one too, it's the whole reason this module can do its thing without C compilation drama, iykyk π
okay that's the whole page bestie, and here's the cute lil sign-off: this doc is from perl v5.36.0, dated 2022-11-19, filed under XML::P...e::Tree(3pm) πΈ go forth and tree-ify some XML, you've got this πβ¨
π¦ where this page comes from
- debian bookworm: libxml-parser-lite-tree-perl 0.14-3 Β· Artistic-2.0
- debian trixie: libxml-parser-lite-tree-perl 0.14-3 Β· Artistic-2.0
- ubuntu noble: libxml-parser-lite-tree-perl 0.14-3 Β· Artistic-2.0
- ubuntu resolute: libxml-parser-lite-tree-perl 0.14-3 Β· Artistic-2.0
- ubuntu stonking: libxml-parser-lite-tree-perl 0.14-3 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms