# phpman > perldoc > XML::LibXML::AttributeHash

## NAME
    [XML::LibXML::AttributeHash](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AAttributeHash/markdown) - tie an [XML::LibXML::Element](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AElement/markdown) to a hash to access its attributes

## SYNOPSIS
     tie my %hash, '[XML::LibXML::AttributeHash](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AAttributeHash/markdown)', $element;
     $hash{'href'} = '<http://example.com/>';
     print $element->getAttribute('href') . "\n";

## DESCRIPTION
    This class allows an element's attributes to be accessed as if they were a plain old Perl hash.
    Attribute names become hash keys. Namespaced attributes are keyed using Clark notation.

     my $XLINK = '<http://www.w3.org/1999/xlink>';
     tie my %hash, '[XML::LibXML::AttributeHash](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AAttributeHash/markdown)', $element;
     $hash{"{$XLINK}href"} = '<http://localhost/>';
     print $element->getAttributeNS($XLINK, 'href') . "\n";

    There is rarely any need to use [XML::LibXML::AttributeHash](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AAttributeHash/markdown) directly. In general, it is possible
    to take advantage of [XML::LibXML::Element](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AElement/markdown)'s overloading. The example in the SYNOPSIS could have
    been written:

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

    The tie interface allows the passing of additional arguments to [XML::LibXML::AttributeHash](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AAttributeHash/markdown):

     tie my %hash, '[XML::LibXML::AttributeHash](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AAttributeHash/markdown)', $element, %args;

    Currently only one argument is supported, the boolean "weaken" which (if true) indicates that
    the tied object's reference to the element should be a weak reference. This is used by
    [XML::LibXML::Element](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AElement/markdown)'s overloading. The "weaken" argument is ignored if you don't have a working
    [Scalar::Util::weaken](https://www.chedong.com/phpMan.php/perldoc/Scalar%3A%3AUtil%3A%3Aweaken/markdown).

