Reputation: 151
I have the following xml snippet:
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="hxxp://foo"
xmlns:xsi="hxxp://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="hxxp://www.w3.org/2001/XMLSchema">
<Child xsi:type="SomeType" xmlns="hxxp://bar">
...
</Child>
</Root>
The question now is: Does SomeType belong to hxxp://foo or hxxp://bar?
I tried to understand http://www.w3.org/TR/REC-xml-names/ and http://www.w3.org/TR/xmlschema-1/ but I'm not sure how to interpret the definition.
Upvotes: 4
Views: 733
Reputation: 1237
(ignore this response -- I misread the question, sorry!)
Because it has an explicit namespace prefix ("xsi:"), the attribute whose value is "SomeType" is in that namespace (which in turn is declared to map to the XML Schema Instance namespace).
If you took the "xsi:" prefix off of "xsi:type", then it would use the default namespace that's in effect at that point. According to section 6.2 of the XML Namespaces spec:
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.
So in that case, the in-scope default namespace would be hxxp://bar
Ain't namespaces fun?
Upvotes: -1
Reputation: 25034
Short answer: You are asking, I believe, whether the name SomeType, given as the value of xsi:type in your example, will be taken as the expanded name {hxxp://foo}SomeType or the expanded name {hxxp://bar}SomeType.
(I may be wrong; the other answers seem to believe you are asking what namespace an attribute with an unqualified name has. Perhaps they took "unqualified content of type attribute" to mean "a node of node-type 'attribute' with an unqualified name" instead of "an unqualified QName given as the value of the type
attribute".)
In your example, SomeType will be interpreted as {hxxp://bar}SomeType, because at the point where the attribute-value specification xsi:type="SomeType" occurs in your document, the default namespace is hxxp://bar.
Details:
The relevant rules in XSD 1.0 are: first, clause 1.2.1.2 of Validation Rule: Schema-Validity Assessment (Element) in section 3.3.4 Element Declaration Validation Rules, which can be paraphrased thus:
The decision about which type is named by the QName (if any) in the third bullet item is made in accordance with the Schema Representation Constraint: QName Interpretation in section 3.15.3, which essentially says, in words of several syllables, how to decide what expanded name is represented by a QName.
The rules in XSD 1.1 specify the same behavior and may be slightly easier to follow. There, the crucial rules are the definitions of governing type definition and instance-specified type definition.
Upvotes: 4
Reputation: 163322
The namespaces spec itself is ambivalent on this question. But in every concrete API that I know of, whether its XPath, XSLT, XQuery, or DOM, the interpretation they have taken is that unprefixed attributes are in no namespace. They are NOT in the default namespace.
(This is sometimes expressed in the form that they are "in the null namespace", but this wrongly suggests that there is some namespace which has the property of being null, whereas the namespaces spec is adamant that the collection of names in no namespace do not constitute a namespace as such.)
Upvotes: 2