简体   繁体   中英

Can a QName value be without a prefix?

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM