|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QXmlName Class Reference
[QtXmlPatterns module]

The QXmlName class represents a name for an XML node in a namespace-aware and efficient way. More...

     #include <QXmlName>

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.4.

- List of all members, including inherited members

### Public Types

- typedef Code

### Public Functions

- QXmlName ()
- QXmlName ( QXmlNamePool & namePool, const QString & localName, const QString & namespaceURI = QString(), const QString & prefix = QString() )
- bool isLexicallyEqual ( const QXmlName & other ) const
- bool isNull () const
- QString localName ( const QXmlNamePool & namePool ) const
- QString namespaceUri ( const QXmlNamePool & namePool ) const
- QString prefix ( const QXmlNamePool & namePool ) const
- QString toClarkName ( const QXmlNamePool & namePool ) const
- bool operator!= ( const QXmlName & other ) const
- QXmlName & operator= ( const QXmlName & other )
- bool operator== ( const QXmlName & other ) const

### Related Non-Members

- uint qHash ( const QXmlName & name )

## Detailed Description

The QXmlName class represents a name for an XML node in a namespace-aware and efficient way.

QXmlName represents a name in XML, such as `body` in the namespace http://www.w3.org/1999/xhtml/, in an efficient and safe way. Instances are created using the constructor and localName(), namespaceUri() and prefix() can be used to access the components. QXmlName's default constructor constructs null names.

QXmlName represents names by using a pooling mechanism behind the curtains. One of the side effects of this mechanism, is that QXmlName instances are tied to the QXmlNamePool it was created with. For instance, one cannot call namespaceUri() with a name that was created with another QXmlNamePool. If one do, behavior is undefined. This makes QXmlName efficient to pass around, and its comparison operators are swift too.

### What is a QXmlNameName?

The name of an element or attribute has three components: its namespace URI, a local name, and a prefix. For the purpose of what a name refers to the prefix is insignficant, and is only a mapping to the namespace. For instance, this element node:

     <svg xmlns="http://www.w3.org/2000/svg"/>

and:

     <x:svg xmlns:x="http://www.w3.org/2000/svg"/>

both represents the same name and compares equal.

A local name can never be an empty string, although the prefix and namespace URI can. If the prefix is not empty, the namespace URI cannot be empty. Both the local name and the prefix(when not being empty), must be valid so called NCNames, such as "abc.def" or "abc123", as according to Namespaces in XML 1.0.

See also Namespaces in XML 1.0 (Second Edition), [4] NCName.

## Member Type Documentation

### typedef QXmlName::Code

Stores a namespace URI, local name and prefix.

## Member Function Documentation

### QXmlName::QXmlName ()

Constructs a QXmlName instance that is null.

See also isNull().

### QXmlName::QXmlName ( QXmlNamePool & namePool, const QString & localName, const QString & namespaceURI = QString(), const QString & prefix = QString() )

Constructs a QXmlName instance that inserts localName, namespaceURI and prefix into namePool.

The user guarantees that the string components are valid for a QName. See the description of this class for a summary.

### bool QXmlName::isLexicallyEqual ( const QXmlName & other ) const

Returns `true` if this and other are lexically equal. That is, if their prefix and local names are equal.

### bool QXmlName::isNull () const

Returns true if this QXmlName is uninitialized and does not contain a name at all.

### QString QXmlName::localName ( const QXmlNamePool & namePool ) const

Returns the local name.

namePool is used internally for looking up the string.

### QString QXmlName::namespaceUri ( const QXmlNamePool & namePool ) const

Returns the namespace URI.

namePool is used internally for looking up the string.

### QString QXmlName::prefix ( const QXmlNamePool & namePool ) const

Returns the prefix.

namePool is used internally for looking up the string.

### QString QXmlName::toClarkName ( const QXmlNamePool & namePool ) const

Returns a string that is this QXmlName formatted as a so called Clark Name. For instance, the local name "html" with prefix "x" while residing in the XHTML namespace, would be returned as "{http://www.w3.org/1999/xhtml/}x:html". The local name "QWidget" with an empty namespace, would be returned as "QWidget".

This function can be useful for debugging, or when a name needs to be represented as a string in an informal way. As implemented, a Clark Name cannot be deterministically parsed.

namePool is used internally for looking up the strings.

See also XML Namespaces, James Clark.

### bool QXmlName::operator!= ( const QXmlName & other ) const

Returns the opposite of applying operator==() on this QXmlName and other.

### QXmlName & QXmlName::operator= ( const QXmlName & other )

Assigns other to this and return this.

### bool QXmlName::operator== ( const QXmlName & other ) const

Returns `true` if this QXmlName is equal to other, otherwise `false`.

Two QXmlNames are equal if the namespace URIs and local names they represents are equal. The prefix is ignored.

## Related Non-Members

### uint qHash ( const QXmlName & name )

This is an overloaded member function, provided for convenience.

Computes a hash key based on the local name combined with the namespace URI in name.

That is, the prefix, which only is a syntactical distriction, is ignored.