xs:QName

The primitive type xs:QName represents an XML namespace-qualified name. In XQuery, xs:QName values have three parts: the full namespace URI, the local part of the name, and the prefix. The namespace and the prefix are optional. If a QName does not have a namespace associated with it, it is considered to be in "no namespace."

When used in a query or schema, the lexical representation of an xs:QName has just two parts: an optional prefix and the local part of the name. Based on the prefix, the context is used to determine the namespace URI. If the prefix is not present, either the name is in the default namespace or it is in no namespace at all.

Table B-19 lists some values of the xs:QName type.

Table B-19. Values of the xs:QName type

Values

Explanation

Valid

 
prod:number

Valid assuming the prefix prod is mapped to a namespace in scope

number

Prefix and colon are optional

Invalid

 
:number

An xs:QName must not start with a colon

prod:3rdnumber

The local part must not start with a number; it must be a valid NCName

 

An empty value or zero-length string is not permitted

The prefix itself has no meaning; it is just a placeholder. However, the XQuery processor does keep track of a QName's prefix. This simplifies certain processes such as serializing QNames and casting them to strings.

One of the most common ways of getting an xs:QName is to use the node-name function, which returns the name of an element or attribute as an xs:QName value.

The xs:QName type has a standard constructor that allows a value to be cast from xs:untypedAtomic or from xs:string. However, it has a special constraint that it can only accept a literal xs:string value (not an evaluated expression) as its argument. The value may be prefixed, e.g., prod:number, or unprefixed, e.g., number. If a prefix is used, it must be declared.

Two additional functions can be used to construct xs:QName values: QName and resolve-QName.

Two xs:QName values can be compared using the = and != operators. They are considered equal if they have the exact same namespace URI (based on Unicode code points) and the exact same local name (also based on Unicode code points); the prefixes are ignored. Because the xs:QName type is not ordered, two xs:QName values cannot be compared using the <, <=, >, or >= operators. The xs:QName type is not derived from xs:string, so you cannot compare them to strings directly.

More information on working with qualified names can be found in "Working with Qualified Names" in Chapter 20.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.17.154