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 new AnyEvent::XMPP::Node object, with the node tag name $el in the namespace URI $ns, plus the attributes $attrs. And heads up: $parser must be the instance of AnyEvent::XMPP::Parser that 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) or eq ($node) β€” returns true whether the current element matches the tag name $name in 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) or eq_ns ($node) β€” returns true if the namespace of this instance of AnyEvent::XMPP::Node matches the namespace described by $namespace_or_alias, or the namespace of the $node β€” which has to be another AnyEvent::XMPP::Node instance, no exceptions πŸ’€

For what $namespace_or_alias means, go read "eq" above, it's all explained there 🫢

  • attr ($name) β€” returns the contents of the $name attribute.
  • 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 the AnyEvent::XMPP::Writer object 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 also XML::GDOME::SAX::Builder or XML::Handler::BuildDOM or XML::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 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