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


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