getOrCreatePrefix

open fun getOrCreatePrefix(namespaceUri: String, prefixHint: String? = null, isAttr: Boolean = false): String

Helper function to ensure a namespace is bound to a prefix. Returns either an existing prefix or a newly allocated (unique) one.

The algorithm works as follows:

  1. If the prefixHint is given and it is bound to the given namespaceUri use that.

  2. If the namespaceUri is already bound to a prefix use that.

  3. If the namespaceUri is empty, write a new namespace attribute for the empty prefix to be bound to the empty namespace.

  4. If the prefixHint is given and it is not bound to a namespace, write a new namespace attribute for the prefixHint and the namespaceUri.

  5. Otherwise generate prefixes starting with "ns1". Find the first one not bound to a namespace, write a new namespace attribute for that prefix and the namespaceUri.

Return

The prefix to use

Parameters

namespaceUri

The namespace uri to ensure a prefix for

prefixHint

A hint for the prefix to use. If null no hint is given.

isAttr

If true, the name is for use as attribute, and thus the blank namespace is reserved for blank prefixes.