XML::Li...uteHash(3)

✨ XML::LibXML::AttributeHash ✨

okay bestie, gather round πŸ’– this is XML::LibXML::AttributeHash, a lil Perl class from the User Contributed Perl Documentation crew, and it does ONE thing and does it gorgeously: it ties an XML::LibXML::Element to a hash so you can poke at its attributes like a normal person. no cap. 🫢


🌸 NAME 🌸

XML::LibXML::AttributeHash β€” tie an XML::LibXML::Element to a hash to access its attributes πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

like, literally this:

 tie my %hash, 'XML::LibXML::AttributeHash', $element;
 $hash{'href'} = 'http://example.com/';
 print $element->getAttribute('href') . "\n";

the way that first line just ties it… obsessed. πŸ”₯


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• β€” this class lets you access an element's attributes as if they were a plain old Perl hash. attribute names become hash keys. easy. iconic. periodt.

namespaced attributes? those get keyed using Clark notation. iykyk 😌✨

 my $XLINK = 'http://www.w3.org/1999/xlink';
 tie my %hash, 'XML::LibXML::AttributeHash', $element;
 $hash{"{$XLINK}href"} = 'http://localhost/';
 print $element->getAttributeNS($XLINK, 'href') . "\n";

ngl, there's rarely any need to use XML::LibXML::AttributeHash directly. in general you can just take advantage of XML::LibXML::Element's overloading β€” main character energy, she handles it for you πŸ’β€β™€οΈ. the example in the SYNOPSIS could have been written like:

 $element->{'href'} = 'http://example.com/';
 print $element->getAttribute('href') . "\n";

see? same vibe, less typing. slay. πŸ’…


πŸ’œ the tie interface & extra args πŸ’œ

the tie interface lets you pass additional arguments to XML::LibXML::AttributeHash:

 tie my %hash, 'XML::LibXML::AttributeHash', $element, %args;

right now only one argument is supported: the boolean weaken. if it's true, it means the tied object's reference to the element should be a weak reference. this is used by XML::LibXML::Element's overloading. 🧚

⚠️ heads up bestie β€” the weaken argument is ignored if you don't have a working Scalar::Util::weaken. so don't come crying to me when it silently does nothing πŸ˜­πŸ™ˆ

and that's the whole page fr fr πŸ“ go forth and tie ur hashes, you absolute legend πŸ‘‘

perl v5.42.2 Β· 2026-05-25 Β· User Contributed Perl Documentation β€” mwah, ily, see u next manpage πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from