Map class

A Map object (that is, an instance of the Map class) holds a set of mappings from an XML namespace prefix to a full namespace URI. These mappings are used for resolving namespace prefixes in XML element and attribute names. See also XPath expressions, XMP location paths and the Node class in the XML module.

Constructing Map objects

There is no direct constructor for Map objects. Instead the Dataset class (in the Metadata module) and the Document class (in the XML module) offer functions to obtain a new Map object. Each class offers two distinct functions:


In case the script developer can easily determine the set of prefix mappings used by a script, the preferred mechanism is to add that list of prefix mappings to a newly obtained empty prefix map. In reality however this is not always practical. For example, a query expression (with prefixes) might be provided by a user at run-time and the script developer may wish to avoid exposing the complexity involving namespaces to the user.

With the default prefix map the query expression can use any of the prefixes that occur in the backing file. While this is certainly not according to the book, the conventions for the use of prefixes are often stable enough to allow this sort of convenience trick.

Adding/accessing mappings in a Map object

put( prefix: String, namespaceURI: String )

Adds the specified prefix to URI mapping to the map, replacing the previous mapping for this prefix if any.

get( prefix: String ) : String

Returns the URI mapped to the specified prefix or null if there is no mapping for the prefix.