XML::Li...mespace(3)
β¨ XML::LibXML::Namespace β¨
okay bestie, gather round, because today we're talking about XML::LibXML::Namespace β the XML::LibXML Namespace Implementation, aka the tiny chaotic gremlin of the XML::LibXML family that's technically not even a real node but acts like one anyway π
π SYNOPSIS π
use XML::LibXML;
# Only methods specific to Namespace nodes are listed here,
# see the XML::LibXML::Node manpage for other methods
my $ns = XML::LibXML::Namespace->new($nsURI);
print $ns->nodeName();
print $ns->name();
$localname = $ns->getLocalName();
print $ns->getData();
print $ns->getValue();
print $ns->value();
$known_uri = $ns->getNamespaceURI();
$known_prefix = $ns->getPrefix();
$key = $ns->unique_key();
π¦ DESCRIPTION π¦
so namespace nodes show up in two ways, and both are iconic:
- when you run
$element->findnodes('namespace::foo'), or - when you call
$node->getNamespaces()
and that's the vibe.
now for the tea β: the namespace node API is not part of any current DOM API, which is why it's so minimal. like, it's giving "we did the bare minimum and honestly? valid."
the big thing to internalise: namespace nodes are not a sub class of XML::LibXML::Node. nope. not even a little. BUT β and this is the plot twist β they act a lot like attribute nodes, so the similarly named methods will return exactly what you'd expect if you just treated the namespace node as an attribute. main character energy fr.
also heads up π¨: in order to fix several inconsistencies between the API and the documentation, the behavior of some functions have been changed in 1.64. so if you're on old code and something's acting different, that's why bestie.
π METHODS π
πΈ new πΈ
my $ns = XML::LibXML::Namespace->new($nsURI);
Creates a new Namespace node. and yes, it's called a node, but lowkey it's not a 'node' like an attribute or an element node is. so no, you can't just call all XML::LibXML::Node Functions on it, sorry babe π. every function that is available for this node is listed right here below, that's the whole menu.
Optionally you can pass the prefix to the namespace constructor. If this second parameter is omitted you will create a so called default namespace. so cute, so mysterious.
note: the newly created namespace is not bound to any document or node, therefore you should not expect it to be available in an existing document. it's free-floating. unbothered. in its own era. π¦
π declaredURI π
Returns the URI for this namespace. that's it, that's the tweet.
π declaredPrefix π
Returns the prefix for this namespace. iconic.
β nodeName β
print $ns->nodeName();
Returns "xmlns:prefix", where prefix is the prefix for this namespace.
β name β
print $ns->name();
Alias for nodeName(). same energy, different name.
π getLocalName π
$localname = $ns->getLocalName();
Returns the local name of this node as if it were an attribute β that is, the prefix associated with the namespace. yes bestie, it's giving "attribute cosplay" and it's serving.
π getData π
print $ns->getData();
Returns the URI of the namespace, i.e. the value of this node as if it were an attribute. the attribute bit is doing a lot of heavy lifting here but okay werk.
π getValue π
print $ns->getValue();
Alias for getData().
π value π
print $ns->value();
Alias for getData(). three names, one behaviour, that's called range π
π getNamespaceURI π
$known_uri = $ns->getNamespaceURI();
Returns the string "http://www.w3.org/2000/xmlns/" β yes it's literally just that, always, no surprises, no cap.
π getPrefix π
$known_prefix = $ns->getPrefix();
Returns the string "xmlns". short king.
π§ unique_key π§
$key = $ns->unique_key();
This method returns a key guaranteed to be unique for this namespace, and to always be the same value for this namespace. Two namespace objects return the same key if and only if they have the same prefix and the same URI. The returned key value is useful as a key in hashes. so if you're building a hash map of namespaces, this is your girl π«Ά
π AUTHORS π
Matt Sergeant, Christian Glahn, Petr Pajas
β VERSION β
2.0213
π COPYRIGHT π
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.
and that's the whole page bestie!! no notes, 10/10, would namespace again β¨ this absolute banger of a manual page comes to you courtesy of the User Contributed Perl Documentation, perl v5.42.2, dated 2026-05-25 β mwah, slay, periodt πππ¦
π¦ where this page comes from
- fedora 43: perl-XML-LibXML 1:2.0213-1.fc43 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND MIT
- fedora 44: perl-XML-LibXML 1:2.0213-1.fc44 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms