class namespace_manager :
object
.. end
method add_uri : string -> string -> unit
This class manages mappings from URIs to normalized prefixes. For every
namespace a namespace_manager object contains a set of mappings
uri1 |-> np, uri2 |-> np, ..., uriN |-> np.
The normalized prefix np is characterstic of the namespace, and
identifies the namespace uniquely.
The first URI uri1 is the primary URI, the other URIs are aliases.
The following operations are supported:
- add_uri np uri: The passed uri is added to the already existing
namespace which is identified by the normprefix np. This means
that the precondition is that there is already some mapping
uri' |-> np, and that there is no mapping for uri. Postcondition
is that uri |-> np is a new mapping.
add_uri thus adds a new alias URI for an existing namespace.
- add_namespace np uri: Precondition is that neither np nor uri
are used in the namespace_manager object. The effect is that the
mapping uri |-> np is added.
- lookup_or_add_namespace p uri: If there is already some mapping
uri |-> np, the normprefix np is simply returned ("lookup"). In this
case p is ignored. Otherwise uri is not yet mapped, and in this
case some unique np must be found such that uri |-> np can be
added ("add_namespace"). First, the passed prefix p is tried.
If p is free, it can be taken as new normprefix: np = p. Otherwise
some number n is found such that the concatenation p + n is free:
np = p + n. The operation returns np.
add_uri np uri: adds uri as alias URI to the namespace identified
by the normprefix np (see above for detailed semantics). The method
raises Namespace_prefix_not_managed if the normprefix np is unknown
to the object,
and it fails (Namespace_error) if the uri is member of a
different namespace. Nothing happens if the uri is already member
of the namespace np.
CHANGE IN PXP 1.2: Using exception Namespace_prefix_not_managed
instead of Not_found.
method add_namespace : string -> string -> unit
add_namespace np uri: adds a new namespace to the object. The
namespace is identified by the normprefix np and contains initially
the primary URI uri.
The method fails (Namespace_error) if either np already identifies
some namespace or if uri is already member of some namespace.
Nothing happens if uri is the sole member of the namespace np.
It is required that np <> "".
method lookup_or_add_namespace : string -> string -> string
lookup_or_add_namespace p uri: first, the method looks up if
the namespace for uri does already exist. If so, p is ignored,
and the method returns the normprefix identifying the namespace.
Otherwise, a new namespace is added for some normprefix np which
initially contains uri. The normprefix np is calculated upon p
serving as suggestion for the normprefix. The method returns
the normprefix.
method get_primary_uri : string -> string
Return the primary URI for a normprefix, or raises
Namespace_prefix_not_managed. get_uri "" raises always this
exception.
CHANGE IN PXP 1.2: Using exception Namespace_prefix_not_managed
instead of Not_found.
method get_uri_list : string -> string list
Return all URIs for a normprefix, or [] if the normprefix is
unused. get_uri_list "" returns always []. The last URI of the
returned list is the primary URI.
method get_normprefix : string -> string
Return the normprefix for a URI, or raises
Namespace_not_managed.
CHANGE IN PXP 1.2: Using exception Namespace_not_managed
instead of Not_found.
method iter_namespaces : (string -> unit) -> unit
Iterates over all namespaces contained in the object, and
calls the passed function for every namespace. The argument of the
invoked function is the normprefix of the namespace.
method as_declaration : (string * string) list
Returns the list of normprefixes and primary URIs. Useful
to create the corresponding namespace scope, e.g.
new namespace_scope_impl mng None (mng#as_declaration)
Encodings: prefixes and URIs are always encoded in the default
encoding of the document