Table of contentsAppendices |
B.1 Namespace NormalizationNamespace Normalization
Namespace declaration attributes and prefixes are normalized as
part of the
void Element.normalizeNamespaces()
{
// Pick up local namespace declarations
//
for ( all DOM Level 2 valid local namespace declaration attributes of Element )
{
if (the namespace declaration is invalid)
{
// Note: The prefix xmlns is used only to declare namespace bindings and
// is by definition bound to the namespace name http://www.w3.org/2000/xmlns/.
// It must not be declared. No other prefix may be bound to this namespace name.
==> Report an error.
}
else
{
==> Record the namespace declaration
}
}
// Fixup element's namespace
//
if ( Element's namespaceURI != null )
{
if ( Element's prefix/namespace pair (or default namespace,
if no prefix) are within the scope of a binding )
{
==> do nothing, declaration in scope is inherited
See section "B.1.1: Scope of a binding" for an example
}
else
{
==> Create a local namespace declaration attr for this namespace,
with Element's current prefix (or a default namespace, if
no prefix). If there's a conflicting local declaration
already present, change its value to use this namespace.
See section "B.1.2: Conflicting namespace declaration" for an example
// NOTE that this may break other nodes within this Element's
// subtree, if they're already using this prefix.
// They will be repaired when we reach them.
}
}
else
{
// Element has no namespace URI:
if ( Element's localName is null )
{
// DOM Level 1 node
==> if in process of validation against a namespace aware schema
(i.e XML Schema) report a fatal error: the processor can not recover
in this situation.
Otherwise, report an error: no namespace fixup will be performed on this node.
}
else
{
// Element has no pseudo-prefix
if ( there's a conflicting local default namespace declaration
already present )
{
==> change its value to use this empty namespace.
}
// NOTE that this may break other nodes within this Element's
// subtree, if they're already using the default namespaces.
// They will be repaired when we reach them.
}
}
// Examine and polish the attributes
//
for ( all non-namespace Attrs of Element )
{
if ( Attr[i] has a namespace URI )
{
if ( attribute has no prefix (default namespace decl does not apply to attributes)
OR
attribute prefix is not declared
OR
conflict: attribute has a prefix that conflicts with a binding
already active in scope)
{
if (namespaceURI matches an in scope declaration of one or more prefixes)
{
// pick the most local binding available;
// if there is more than one pick one arbitrarily
==> change attribute's prefix.
}
else
{
if (the current prefix is not null and it has no in scope declaration)
{
==> declare this prefix
}
else
{
// find a prefix following the pattern "NS" +index (starting at 1)
// make sure this prefix is not declared in the current scope.
// create a local namespace declaration attribute
==> change attribute's prefix.
}
}
}
}
else
{
// Attr[i] has no namespace URI
if ( Attr[i] has no localName )
{
// DOM Level 1 node
==> if in process of validation against a namespace aware schema
(i.e XML Schema) report a fatal error: the processor can not recover
in this situation.
Otherwise, report an error: no namespace fixup will be performed on this node.
}
else
{
// attr has no namespace URI and no prefix
// no action is required, since attrs don't use default
==> do nothing
}
}
} // end for-all-Attrs
// do this recursively
for ( all child elements of Element )
{
childElement.normalizeNamespaces()
}
} // end Element.normalizeNamespaces
Scope of a Binding[top]Scope of a BindingNOTE: An element's prefix/namespace URI pair is said to be within the scope of a binding if its namespace prefix is bound to the same namespace URI in the [in-scope namespaces] defined in [InfoSet]. As an example, the following document is loaded in a DOM tree:
<root>
<parent xmlns:ns="http://www.example.org/ns1"
xmlns:bar="http://www.example.org/ns2">
<ns:child1 xmlns:ns="http://www.example.org/ns2"/>
</parent>
</root>
In the case of the
Using the method
<root>
<parent xmlns:ns="http://www.example.org/ns1"
xmlns:bar="http://www.example.org/ns2">
<ns:child1 xmlns:ns="http://www.example.org/ns2"/>
<ns:child2 xmlns:ns="http://www.example.org/ns2"/>
</parent>
</root>
To determine if an element is within the scope of a binding, one
can invoke Conflicting Namespace Declaration[top]Conflicting Namespace DeclarationNOTE:
A conflicting namespace declaration could occur on an element if
an As an example, the following document is loaded in a DOM tree:
<root>
<ns:child1 xmlns:ns="http://www.example.org/ns1">
<ns:child2/>
</ns:child1>
</root>
Using the method
<root>
<ns:child1 xmlns:ns="http://www.example.org/ns2">
<ns:child2 xmlns:ns="http://www.example.org/ns1"/>
</ns:child1>
</root>
|