Go to main content

man pages section 3: Library Interfaces and Headers

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

XML::LibXML::AttributeHash (3)

Name

XML::LibXML::AttributeHash - tie an XML::LibXML::Element to a hash to access its attributes

Synopsis

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

Description

User Contributed Perl Documentation
                                                 XML::LibXML::AttributeHash(3)



NAME
       XML::LibXML::AttributeHash - tie an XML::LibXML::Element to a hash to
       access its attributes

SYNOPSIS
        tie my %hash, 'XML::LibXML::AttributeHash', $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', $element;
        $hash{"{$XLINK}href"} = 'http://localhost/';
        print $element->getAttributeNS($XLINK, 'href') . "\n";

       There is rarely any need to use XML::LibXML::AttributeHash directly. In
       general, it is possible to take advantage of XML::LibXML::Element'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:

        tie my %hash, 'XML::LibXML::AttributeHash', $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's
       overloading. The "weaken" argument is ignored if you don't have a
       working Scalar::Util::weaken.



ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:


       +---------------+-------------------------------+
       |ATTRIBUTE TYPE |       ATTRIBUTE VALUE         |
       +---------------+-------------------------------+
       |Availability   | library/perl-5/xml-libxml-532 |
       +---------------+-------------------------------+
       |Stability      | Volatile                      |
       +---------------+-------------------------------+

NOTES
       Source code for open source software components in Oracle Solaris can
       be found at https://www.oracle.com/downloads/opensource/solaris-source-
       code-downloads.html.

       This software was built from source available at
       https://github.com/oracle/solaris-userland.  The original community
       source was downloaded from
       http://search.cpan.org/CPAN/authors/id/S/SH/SHLOMIF/XML-
       LibXML-2.0201.tar.gz.

       Further information about this software can be found on the open source
       community website at http://search.cpan.org/~shlomif/XML-LibXML/.



perl v5.32.0                      2019-05-25
                                                 XML::LibXML::AttributeHash(3)