AnyEven...P::Node(3)
π AnyEvent::XMPP::Node β from the User Contributed Perl Documentation besties π
okay so real talk: this is the AnyEvent::XMPP::Node(3) page, and it's literally the XML node tree helper for the parser. That's the whole vibe. β¨
πΈ SYNOPSIS πΈ
use AnyEvent::XMPP::Node;
...
that's it, that's the synopsis, she's lowkey minimal and we respect it π«Ά
π¦ DESCRIPTION π¦
So this class represents an XML node. That's the whole job. Now β and this is the important part β AnyEvent::XMPP should usually not require you to be messing with the parse tree at all. Like, normally? hands off. But sometimes it is necessary, and that's why this class exists π
And listen: if you ever find yourself experiencing any need to mess with these, and you're like "hmm, AnyEvent::XMPP should probably just take care of this itself" β please drop the author a mail, or a feature request, or most preferably a patch! fr fr, patches are the love language π
Every single AnyEvent::XMPP::Node has a namespace, attributes, text, and child nodes. All four. No cap.
You can access all of these with the following methods π
β¨ METHODS β¨
new ($ns, $el, $attrs, $parser)β Creates a brand newAnyEvent::XMPP::Nodeobject, with the node tag name$elin the namespace URI$ns, plus the attributes$attrs. And heads up:$parsermust be the instance ofAnyEvent::XMPP::Parserthat generated this node. Not a lookalike, not a cousin β that one. π§nameβ the tag name of this node. that's her. that's the whole method. iconic.namespaceβ returns the namespace URI of this node πeq ($namespace_or_alias, $name)oreq ($node)β returns true whether the current element matches the tag name$namein the namespaces pointed at by$namespace_or_alias.
You've got options here bestie: you can either pass an alias that was defined in AnyEvent::XMPP::Namespaces, or pass a namespace URI in $namespace_or_alias. And if no alias with the name $namespace_or_alias was found in AnyEvent::XMPP::Namespaces, it will be interpreted as a namespace URI. Automatic fallback, we love a flexible queen π
Also! The first argument to eq can also be another AnyEvent::XMPP::Node instance. slay.
eq_ns ($namespace_or_alias)oreq_ns ($node)β returns true if the namespace of this instance ofAnyEvent::XMPP::Nodematches the namespace described by$namespace_or_alias, or the namespace of the$nodeβ which has to be anotherAnyEvent::XMPP::Nodeinstance, no exceptions π
For what $namespace_or_alias means, go read "eq" above, it's all explained there π«Ά
attr ($name)β returns the contents of the$nameattribute.add_node ($node)β adds a sub-node to the current node. nesting time πͺnodesβ returns a list of sub nodes.add_text ($string)β adds character data to the current node.textβ returns the text for this node.find_all (@path)β this method does a recursive descent through the sub-nodes and fetches all the nodes that match the last element of@path.
And what's in @path? Each element of @path consists of an array reference to an array with two elements: the namespace key known by the $parser, and the tagname we search for. Two things. That's the whole tuple. π₯
write_on ($writer)β writes the current node out to theAnyEvent::XMPP::Writerobject in$writer.as_string ()β returns the original character representation of this XML element (and its children nodes).
β οΈ important caveat incoming: please note that the string is a unicode string, meaning: to get octets use:
my $octets = encode ('UTF-8', $node->as_string);
And now that you've got octets, you can roll stunts like this ππ₯:
my $libxml = XML::LibXML->new;
my $doc = $libxml->parse_string (encode ('UTF-8', $node->as_string ()));
(You can use your favorite XML parser :) β go off, pick your fave, no judgement here π)
append_raw ($string)β this method is called by the parser to store original strings of this element. (so like, it's the parser's method really, you're just visiting π)to_sax_events ($handler)β this method takes anything that can receive SAX events. See alsoXML::GDOME::SAX::BuilderorXML::Handler::BuildDOMorXML::LibXML::SAX::Builder.
And with this you can convert this node to any DOM level 2 structure you want. any. you. want. π
my $builder = XML::LibXML::SAX::Builder->new;
$node->to_sax_events ($builder);
my $dom = $builder->result;
print "Canonized: " . $dom->toStringC14N . "\n";
π AUTHOR π
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>" β absolute legend, we stan π
π COPYRIGHT & LICENSE π
Copyright 2007, 2008 Robin Redeker, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt. π
and that's the page!! this lil beauty shipped as perl v5.42.2, dated 2026-02-15, and the manual name on the tin is User Contributed Perl Documentation π¦ mwah, go write some patches bestie π«Άβ¨
π¦ where this page comes from
- alpine 3.24: perl-anyevent-xmpp-doc 0.55-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms