In the below XML snippet what are the namespaces of a, c, d and e? Reference to documentation or specifications would be appreciated.
<a xmlns="http://domain/a">
<pre:b xmlns:pre="http://domain/b">
<c/>
<d xmlns="">
<e/>
</d>
</pre:b>
</a>
Also, what Java frameworks respect the official namespace defaulting? I have tride org.w2c.* DOM packages, however it does not seem to resolve the namespace URI correctly? For example, something with similar functionality to.
String namespace = DocumentParser.parse().
getElement("a").
getElement("b").
getElement("c").
getNamespaceURI();
From what I can tell it would be as follows.
I am basing this off of this specification. Below is a summary quote to help as well.
If there is a default namespace declaration in scope, the expanded name corresponding to an unprefixed element name has the URI of the default namespace as its namespace name. If there is no default namespace declaration in scope, the namespace name has no value. The namespace name for an unprefixed attribute name always has no value. In all cases, the local name is local part (which is of course the same as the unprefixed name itself).
A namespace declared using xmlns="..."
becomes the default for any elements within it (until the default is then redeclared in a deeper element, of course). So you end up with:
The relevant spec section is the XML names spec, section 6.2:
The scope of a default namespace declaration extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner default namespace declarations. In the case of an empty tag, the scope is the tag itself.
A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear.
If there is a default namespace declaration in scope, the expanded name corresponding to an unprefixed element name has the URI of the default namespace as its namespace name. If there is no default namespace declaration in scope, the namespace name has no value. The namespace name for an unprefixed attribute name always has no value. In all cases, the local name is local part (which is of course the same as the unprefixed name itself).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With