View on GitHub


Raku bindings to the libxml2 native library

class LibXML::Namespace

LibXML Namespace implementation


use LibXML::Namespace;
my LibXML::Namespace $ns .= new(:$URI, :$prefix);
say $ns.nodeName();
say $;
my Str $localname = $ns.localname();
say $ns.getValue();
say $ns.value();
my Str $known-uri = $ns.getNamespaceURI();
my Str $known-prefix = $ns.prefix();
$key = $ns.unique-key();


Namespace nodes are returned by both $element.findnodes(‘namespace::foo’) or by $node.getNamespaces().

The namespace node API is not part of any current DOM API, and so it is quite minimal. It should be noted that namespace nodes are not a sub class of LibXML::Node, however Namespace nodes act a lot like attribute nodes (both are based on LibXML::Item). Similarly named methods return what you would expect if you treated the namespace node as an attribute.


method new

method new(Str:D :$URI!, NCName :$prefix, LibXML::Node :$node)
    returns LibXML::Namespace

Creates a new Namespace node. Note that this is not a ‘node’ as an attribute or an element node. Therefore you can’t do call all LibXML::Node Functions. All functions available for this node are listed below.

Optionally you can pass the prefix to the namespace constructor. If :$prefix is omitted you will create a so called default namespace. 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.

method declaredURI

method declaredURI() returns Str

Returns the URI for this namespace

method declaredPrefix

method declaredPrefix() returns LibXML::Types::NCName

Returns the prefix for this namespace

method nodeName

method nodeName() returns Str

Returns “xmlns:prefix”, where prefix is the prefix for this namespace.

method name

Alias for nodeName()

method unique-key

method unique-key() returns Str

Return a unique key for the namespace

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.

method getNamespaceURI

method getNamespaceURI() returns Str

Returns the string “”

method prefix

method prefix() returns Str

Returns the string “xmlns”

2001-2007, Ltd.

2002-2006, Christian Glahn.

2006-2009, Petr Pajas.


This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0