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 β theweakenargument is ignored if you don't have a workingScalar::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
- fedora 43: perl-XML-LibXML 1:2.0213-1.fc43 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND MIT
- fedora 44: perl-XML-LibXML 1:2.0213-1.fc44 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms