XML::LibXML::Attr(3)

πŸ’– XML::LibXML::Attr β€” the XML::LibXML Attribute Class πŸ’–

okay bestie, welcome to the manual page for XML::LibXML::Attr(3) β€” it lives in the User Contributed Perl Documentation section, and it's literally the glow-up guide for attribute nodes. no cap. πŸŽ€


✨ SYNOPSIS ✨

use XML::LibXML;
# Only methods specific to Attribute nodes are listed here,
# see the XML::LibXML::Node manpage for other methods

$attr = XML::LibXML::Attr->new($name [,$value]);
$string = $attr->getValue();
$string = $attr->value;
$attr->setValue( $string );
$node = $attr->getOwnerElement();
$attr->setNamespace($nsURI, $prefix);
$bool = $attr->isId;
$string = $attr->serializeContent;

🌸 DESCRIPTION 🌸

so basically this is the interface for handling Attributes like they're ordinary nodes β€” very "everyone's equal, even the little ones" of it. 🫢

the naming of the class is fully faithful to the W3C DOM documentation, so if you know that, you already know the vibe.


πŸ‘‘ METHODS πŸ‘‘

this class inherits from XML::LibXML::Node, and the docs for inherited methods are not listed here (go read the parent, she's serving too). πŸ’…

a lot of these functions are extensively documented in the DOM Level 3 specification (<http://www.w3.org/TR/DOM-Level-3-Core/>). please refer to the spec for the extended lore, bestie. πŸ“–


πŸ¦‹ new

$attr = XML::LibXML::Attr->new($name [,$value]);

class constructor, iconic behavior. ✨

real talk though: if you need to work with ISO encoded strings, you should always use the createAttribute of XML::LibXML::Document instead. don't do it any other way, i'm begging. 😭

πŸ“ getValue

$string = $attr->getValue();

returns the value stored for the attribute. πŸ’–

if undef gets returned, that means the attribute has no value β€” which is different from being "not specified". the distinction is real, don't blur it. πŸ™ˆ


🧚 value

$string = $attr->value;

alias for getValue(). same energy, shorter name. slay. πŸ’…


🌈 setValue

$attr->setValue( $string );

this is needed to set a new attribute value. periodt.

if ISO encoded strings are passed as the parameter, the node has to be bound to a document β€” otherwise the encoding might be done incorrectly. so like, bind first, then encode. no skipping steps. πŸ’€


πŸ’œ getOwnerElement

$node = $attr->getOwnerElement();

returns the node the attribute belongs to. 🫢

if the attribute is not bound to a node, undef will be returned. and here's the tea: overwriting the underlying implementation, the parentNode function will return undef β€” instead of the owner element. yes, that's intentional. πŸ‘‘


πŸŽ€ setNamespace

$attr->setNamespace($nsURI, $prefix);

this function tries to bound the attribute to a given namespace. okay so here's the whole breakdown, listen carefully:

  • if $nsURI is undefined or empty, the function discards any previous association of the attribute with a namespace.
  • if the namespace was not previously declared in the context of the attribute, this function will fail. in that case you may wish to call setNamespace() on the ownerElement instead. πŸ‘ˆ
  • if the namespace URI is non-empty and declared in the context of the attribute, but only with a different (non-empty) prefix, then the attribute is still bound to the namespace β€” but it gets a different prefix than $prefix.
  • the function also fails if the prefix is empty but the namespace URI is not β€” because unprefixed attributes should by definition belong to no namespace. that's just the rules, babe. πŸ’…

this function returns 1 on success, 0 otherwise. ✨


⭐ isId

$bool = $attr->isId;

determine whether an attribute is of type ID. πŸ”

  • for documents with a DTD, this info is only available if DTD loading/validation has been requested.
  • for HTML documents parsed with the HTML parser, ID detection is done automatically. πŸ€–
  • in XML documents, all xml:id attributes are considered to be of type ID. periodt.

🌸 serializeContent($docencoding)

$string = $attr->serializeContent;

heads up: this function is not part of DOM API. 🚫

it returns attribute content in the form in which it serializes into XML β€” that is, with all meta-characters properly quoted and with raw entity references (except for entities expanded during parse time). so it's giving... exact XML realness. πŸ’–

setting the optional $docencoding flag to 1 enforces document encoding for the output string (which is then passed to Perl as a byte string). otherwise the string is passed to Perl as (UTF-8 encoded) characters. pick your fighter. βš”οΈ


πŸ’… AUTHORS πŸ’…

Matt Sergeant, Christian Glahn, Petr Pajas β€” the founding mothers, we stan. πŸ‘‘


⭐ VERSION ⭐

2.0213


  • 2001-2007, AxKit.com Ltd.
  • 2002-2006, Christian Glahn.
  • 2006-2009, Petr Pajas.

🌈 LICENSE 🌈

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay that's the whole page, bestie!! πŸ’–βœ¨ this was XML::LibXML::Attr(3), brought to you by perl v5.42.2 on 2026-05-25, courtesy of User Contributed Perl Documentation. go forth and attribute responsibly. mwah. πŸ«ΆπŸ’‹

πŸ“¦ where this page comes from