XML Namespace Declaration
A namespace declaration is an attribute with a fixed name xmlns
, and
which can occur multiple times in one start tag.
<tagName
xmlns
{:
Prefix}=
URI>
…</
tagName>
Description
If xmlns
is followed by a colon and a name, that name is the so-called
prefix or alias of the namespace. The namespace itself is a URI. When a subsequent element or
attribute (or even the element in which the namespace is being declared) uses the same prefix, its
URI is deemed to be the one with which it was declared.
Conversion to Struct
When converted without the /full
switch, namespace declarations are
ignored.
When converted with the /full
switch, a namespace declaration converts to
a Struct called by the prefix (if specified) or #default
(if
no prefix is declared), and the xmlClass
attribute set to
namespace-declaration
.
Annotations
The Struct for the namespace gets only one annotation
(xmlClass=namespace-declaration
), but an element or attribute with a namespace
prefix has the xmlNamespaceAlias = prefix
and
xmlNamespaceURI = uri
tags set. This also applies to the
element in which the namespace is declared.
XML to Struct Conversion: Namespaces
XML with namespace declaration and use of prefix:
<doc xmlns:ss="name://Space" xmlns='name://Default'> <p class="note" ss:type="caution">Be careful. </p></doc>
String returned by $dbgString (after conversion with
/full
):
[] [doc] [$tags] [xmlClass] = element [xmlNamespaceURI] = name://Default [ss] = name://Space [$tags] [xmlClass] = namespace-declaration [#default] = name://Default [$tags] [xmlClass] = namespace-declaration [p] [$tags] [xmlClass] = element [xmlNamespaceURI] = name://Default [class] = note [$tags] [xmlClass] = attribute [type] = caution [$tags] [xmlClass] = attribute [xmlNamespaceURI] = name://Space [xmlNamespaceAlias] = ss [] = Be careful.
- Namespace is declared in
doc
element, so it getsxmlNamespaceURI
annotation. - Namespace declaration with prefix (alias)
- Default namespace declaration (without prefix)
- The
p
element does not specify a prefix, so it gets the default namespace. - Default namespace declarations do not apply directly to attribute names.
- The type attribute is preceded by the prefix, so it gets the namespace declared for
ss
. Both thexmlNamespaceURI
andxmlNamespaceAlias
attributes are set.