3

Suppose an element is declared to be of type QName:

<element name="example" type="QName" />

In an instance document, can the value of example be without a namespace prefix:

<example>Hello</example>

If yes, then what is the namespace URI for Hello?

Suppose I declare a default namespace:

<document xmlns="http://www.example.org">
    <example>Hello</example>
</document>

Is Hello in the http://www.example.org namespace?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Roger Costello
  • 3,007
  • 1
  • 22
  • 43

2 Answers2

1

The content obeys the same rules as for element (rather than attribute) names. A QName without a prefix is interpreted as being in the default namespace declared in the instance by the nearest containing element with an xmlns attribute, or in no-namepace if no namespace is declared. So, yes, Hello would be interpreted as a QName denoting a name in that namespace.

james.garriss
  • 12,959
  • 7
  • 83
  • 96
David Carlisle
  • 5,582
  • 1
  • 19
  • 23
0

Hello is a value and not an element or attribute name, and as such it does not have a namespace URI, it is just a string.

The declaration

<element name="example" type="QName" /> 

restrict the possible values of example to strings matching the syntax of a QName (as defined at http://www.w3.org/TR/REC-xml-names/#ns-qualnames - so valid values can be a, a:b and so on), but it does not say that the value IS a QName.

MiMo
  • 11,793
  • 1
  • 33
  • 48
  • 1
    The interpretation that the xml is just a string and not a Qname or an integer or double or any other type is true in some contexts but not in may others, for example xquery and schema aware xslt will return data of the specified type if the input is validated with such a schema. – David Carlisle Mar 18 '12 at 10:34