Reputation: 1920
I have a conceptual confusion on the scope of namespaces in xml esspicially on attributes,consider this example,
<envelope>
<order xmlns="http://example.org/ord" xmlns:prod="http://example.org/prod">
<number>123ABBCC123</number>
<items>
<product xmlns="http://example.org/prod">
<number prod:id="prod557">557</number>
<name xmlns="">Short-Sleeved Linen Blouse</name>
<prod:size system="US-DRESS">10</prod:size>
<prod:color xmlns:prod="http://example.org/prod2" prod:value="blue"/>
</product>
</items>
</order>
</envelope>
What name space is the the attiribute 'system' in ?
Is it in prefixed prod namespace same its element size,
Or is it in default namespace as its parent element product?
Upvotes: 4
Views: 508
Reputation: 163272
It's generally held that attributes with no prefix are in no namespace; certainly that's the way most APIs present them, as well as XQuery, XPath, and XSLT.
I've heard pedants suggest however, that the namespaces specification doesn't actually say this. What the spec actually says is:
Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear.
and apparently the word "directly" was a committee compromise because some people felt that the namespace of unprefixed attributes is actually a matter for the semantics of the XML vocabulary concerned. I've even come across some who assert that this sentence should be read as saying that an unprefixed attribute is in the same namespace as its containing element. However, it's what the XML APIs do that really matters, not what the namespaces spec says.
Upvotes: 4
Reputation: 161773
The answer is "yes".
The prefix prod
refers to the same namespace that is later set as the default on the product
element.
Upvotes: 0