XML::NamespaceSupport 1.09 review

Download
by rbytes.net on

XML::NamespaceSupport is Perl module a simple generic namespace support class. SYNOPSIS use XML::NamespaceSupport; my $nsu

License: Perl Artistic License
File size: 7K
Developer: Robin Berjon
0 stars award from rbytes.net

XML::NamespaceSupport is Perl module a simple generic namespace support class.

SYNOPSIS

use XML::NamespaceSupport;
my $nsup = XML::NamespaceSupport->new;

# add a new empty context
$nsup->push_context;
# declare a few prefixes
$nsup->declare_prefix($prefix1, $uri1);
$nsup->declare_prefix($prefix2, $uri2);
# the same shorter
$nsup->declare_prefixes($prefix1 => $uri1, $prefix2 => $uri2);

# get a single prefix for a URI (randomly)
$prefix = $nsup->get_prefix($uri);
# get all prefixes for a URI (probably better)
@prefixes = $nsup->get_prefixes($uri);
# get all prefixes in scope
@prefixes = $nsup->get_prefixes();
# get all prefixes that were declared for the current scope
@prefixes = $nsup->get_declared_prefixes;
# get a URI for a given prefix
$uri = $nsup->get_uri($prefix);

# get info on a qname (java-ish way, it's a bit weird)
($ns_uri, $local_name, $qname) = $nsup->process_name($qname, $is_attr);
# the same, more perlish
($ns_uri, $prefix, $local_name) = $nsup->process_element_name($qname);
($ns_uri, $prefix, $local_name) = $nsup->process_attribute_name($qname);

# remove the current context
$nsup->pop_context;

# reset the object for reuse in another document
$nsup->reset;

# a simple helper to process Clarkian Notation
my ($ns, $lname) = $nsup->parse_jclark_notation('{http://foo}bar');
# or (given that it doesn't care about the object
my ($ns, $lname) = XML::NamespaceSupport->parse_jclark_notation('{http://foo}bar');

This module offers a simple to process namespaced XML names (unames) from within any application that may need them. It also helps maintain a prefix to namespace URI map, and provides a number of basic checks.

The model for this module is SAX2's NamespaceSupport class, readable at http://www.megginson.com/SAX/Java/javadoc/org/xml/sax/helpers/NamespaceSupport.html. It adds a few perlisations where we thought it appropriate.

Requirements:
Perl

XML::NamespaceSupport 1.09 search tags