XML::E...lement(3pm)
π XML::E...lement β bestie edition π
okay so this is XML::Easy::Element, part of the User Contributed Perl Documentation situation. it's literally the abstract form of an XML element. let's get into it π«Ά
β¨ NAME β¨
XML::Easy::Element β the abstract form of an XML element. that's it, that's the vibe π
πΈ SYNOPSIS πΈ
use XML::Easy::Element;
$element = XML::Easy::Element->new("a", { href => "#there" },
$content);
$type_name = $element->type_name;
$attributes = $element->attributes;
$href = $element->attribute("href");
$content = $element->content_object;
π¦ DESCRIPTION π¦
so an object of this class represents an XML element β a node in the tree that makes up an XML document. it's in an abstract form, which means it's built for general manipulation, not for being pretty. it is completely isolated from the textual representation of XML. it holds only the meaningful content of the element. no extra crumbs, no formatting drama β¨
and here's the thing, bestie: the data in an element object cannot be modified. like, at all. if you want different data, you need to create a whole new object. it's giving "we don't do edits here" π
the properties of an XML element come in three kinds, and yes, we're going through all three:
- firstly, the element has exactly one type, and that type is referred to by a name.
- secondly, the element has a set of zero or more attributes. each attribute is made of a name (which is unique among the attributes of that element) and a value (which is a string of characters).
- finally, the element has content, which is a sequence of zero or more characters and (recursively!) elements, interspersed in any fashion. yes, any fashion. chaotic content is valid content, iconically.
now, the element type name and all the attribute names follow the XML syntax for names. this allows a wide set of Unicode characters, with some restrictions. attribute values and character content can use almost all Unicode characters too β only a few of them (like most of the ASCII control characters) are prohibited by the spec from being directly represented in XML. not me getting fenced in by the specification π
okay, important one: this class is not meant to be subclassed. XML elements are unextendable, dumb data. no glow-ups allowed. also, element objects are better processed using the functions in XML::Easy::NodeBasics than using the methods of this class. fr fr, the functions are the main character here π
π CONSTRUCTOR π
XML::Easy::Element->new(TYPE_NAME, ATTRIBUTES, CONTENT)β constructs and returns a new element object with the properties you specified. let's break down the receipts:TYPE_NAMEmust be a string.ATTRIBUTESmust be a reference to a hash in the exact same form that's returned by the accessor methodattributes(that's the one below, keep scrolling bestie).CONTENTmust be a reference to either anXML::Easy::Contentobject or a twine array (see"Twine"inXML::Easy::NodeBasics).
all of them get checked for validity against the XML 1.0 specification, and if any of them are invalid, the function dies. no soft launches, no second chances β just death π
π METHODS π
$element->type_nameβ returns the element type name, as a string. just the name, bestie β¨$element->attributesβ returns a reference to a hash encapsulating the element's attributes. in that hash, each key is an attribute name, and the corresponding value is that attribute's value as a string.
β οΈ the returned hash must not be subsequently modified. if possible, it will be marked as read-only to prevent modification. and as a side effect, that read-only-ness may make looking up any non-existent attribute generate an exception rather than returning undef. so likeβ¦ watch out, okay? π
$element->attribute(NAME)β looks up one specific attribute of the element. theNAMEyou supply must be a string containing a valid attribute name. if there's an attribute by that name, its value is returned as a string. if there's no such attribute,undefis returned. simple as that πΈ$element->content_objectβ returns a reference to anXML::Easy::Contentobject encapsulating the element's content. iconic content-holder behavior π$element->content_twineβ returns a reference to a twine array (see"Twine"inXML::Easy::NodeBasics) listing the element's content.
β οΈ same deal as before: the returned array must not be subsequently modified. if possible, it will be marked as read-only to prevent modification. no touching π«
$element->contentβ deprecated alias for thecontent_twinemethod. it still works, but it's giving "old money that nobody invites to the party anymore." usecontent_twineinstead π§
π₯ SEE ALSO π₯
XML::Easy::ContentXML::Easy::NodeBasics
go read those too, they're the supporting cast and they ate π
π AUTHOR π
Andrew Main (Zefram) <zefram@fysh.org>
β COPYRIGHT β
Copyright (C) 2008, 2009 PhotoBox Ltd
Copyright (C) 2009, 2010, 2011, 2017 Andrew Main (Zefram) <zefram@fysh.org>
π LICENSE π
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie! this was documented in perl v5.42.3, dated 2026-08-22, and it's part of the XML::E...lement(3pm) situation. slay, go build some XML trees, and remember: the data does not change πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libxml-easy-perl 0.014-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms