All prefixes must be declared before they are referenced.
For example, a SAX driver (parser)
would scan an element's attributes
in two passes: first for namespace declarations,
then a second pass using process_name to
interpret prefixes against (potentially redefined) prefixes.
This method declares a prefix in the current Namespace context; the prefix will remain in force until this context is popped, unless it is shadowed in a descendant context.
To declare the default element Namespace, use the empty string as the prefix.
Note that you must not declare a prefix after you've pushed and popped another Namespace context, or treated the declarations phase as complete by processing a prefixed name.
Note that there is an asymmetry in this library:
prefix will not return the "" prefix,
even if you have declared a default element namespace.
To check for a default namespace,
you have to look it up explicitly using uri.
This asymmetry exists to make it easier to look up prefixes
for attribute names, where the default prefix is not allowed.
Parameters:
prefix: prefix to declare, or the empty string to
indicate the default element namespace. This may never have
the value xml or xmlns.uri: The Namespace URI to associate with the prefix.Returns:
true if the prefix and the URI are legal, false otherwise.
SEE: process_name
SEE: uri
SEE: prefix
# Declare a Namespace prefix.
#
# All prefixes must be declared before they are referenced.
# For example, a SAX driver (parser)
# would scan an element's attributes
# in two passes: first for namespace declarations,
# then a second pass using `process_name` to
# interpret prefixes against (potentially redefined) prefixes.
#
# This method declares a prefix in the current Namespace
# context; the prefix will remain in force until this context
# is popped, unless it is shadowed in a descendant context.
#
# To declare the default element Namespace, use the empty string as
# the prefix.
#
# Note that you must *not* declare a prefix after
# you've pushed and popped another Namespace context, or
# treated the declarations phase as complete by processing
# a prefixed name.
#
# Note that there is an asymmetry in this library:
# `prefix` will not return the `""` prefix,
# even if you have declared a default element namespace.
# To check for a default namespace,
# you have to look it up explicitly using `uri`.
# This asymmetry exists to make it easier to look up prefixes
# for attribute names, where the default prefix is not allowed.
#
# Parameters:
#
# * `prefix`: prefix to declare, or the empty string to
# indicate the default element namespace. This may never have
# the value `xml` or `xmlns`.
# * `uri`: The Namespace URI to associate with the prefix.
#
#
# Returns:
#
# `true` if the prefix and the URI are legal, `false` otherwise.
#
# SEE: `process_name`
#
# SEE: `uri`
#
# SEE: `prefix`
fun declare_prefix(prefix: String, uri: String): Bool do
if prefix == "xml" or prefix == "xmlns" or
uri == xmlns or uri == nsdecl then
return false
else
current_context.declare_prefix(prefix, uri)
return true
end
end
lib/sax/helpers/namespace_support.nit:173,2--227,4