PXP Reference : Pxp_dtd.namespace_manager

# Class Pxp_dtd.namespace_manager

    class namespace_manager : object .. end

This class manages mappings from URIs to normalized prefixes. For every namespace a namespace_manager object contains a set that maps various URI's to the same normalized prefix `np`:

     uri1 |-> np, uri2 |-> np, ..., uriN |-> np

The normalized prefix `np` is characterstical of the namespace, and identifies the namespace uniquely. The first URI `uri1` is the primary URI, the other URIs are aliases.

In order to create an empty namespace, call `Pxp_dtd.create_namespace_manager`.

See `Intro_namespaces` for an introduction to namespaces and more links to other explanations about namespace managers.

The following operations are supported:

- `add_namespace np uri`: adds a new mapping `uri |-> np` to the manager. Neither `np` nor `uri` must already be part of another mapping in the manager.
- `add_uri np uri`: adds a new alias `uri` for an existing namespace which is identified by the normprefix `np`. The normprefix `np` must already be part of a mapping which is then extended by this method.
- `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`.

Encodings: prefixes and URIs are always encoded in the default encoding of the document

    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 add_uri : string -> string -> unit

`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 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.

    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`.

    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)