Comparing QXmlNames
To determine what a QXmlName refers to, the namespace URI and the local name are used. The prefix is not used because the prefix is simply a shorthand name for use in place of the normally much longer namespace URI. Nor is the prefix used in name comparisons. For example, the following two element nodes represent the same element and compare equal.
<svg xmlns="http://www.w3.org/2000/svg"/>
<x:svg xmlns:x="http://www.w3.org/2000/svg"/>
Although the second name has the prefix x, the two names compare equal as instances of QXmlName, because the prefix is not used in the comparison.
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. Local names and prefixes must be valid NCNames, e.g., abc.def or abc123.
QXmlName represents what is sometimes called an expanded QName, or simply a QName.
See also Namespaces in XML 1.0 (Second Edition), [4] NCName.
Member Function Documentation
QXmlName::QXmlName ()
Constructs an uninitialized QXmlName. To build a valid QXmlName, you normally use the other constructor, which takes a name pool, namespace URI, local name, and prefix as parameters. But you can also use this constructor to build a null QXmlName and then assign an existing QXmlName to it.
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 if they aren't already there. The accessor functions namespaceUri(), prefix(), localName(), and toClarkName() must be passed the namePool used here, so the namePool must remain in scope while the accessor functions might be used. However, two instances can be compared with == or != and copied without the namePool.
The user guarantees that the string components are valid for a QName. In particular, the local name, and the prefix (if present), must be valid NCNames. The function isNCName() can be used to test validity of these names. The namespace URI should be an absolute URI. QUrl::isRelative() can be used to test whether the namespace URI is relative or absolute. Finally, providing a prefix is not valid when no namespace URI is provided.
namePool is not copied. Nor is the reference to it retained in this instance. This constructor inserts the three strings into namePool.
bool QXmlName::isNCName ( const QString & candidate ) [static]
Returns true if candidate is an NCName. An NCName is a string that can be used as a name in XML and XQuery, e.g., the prefix or local name in an element or attribute, or the name of a variable.
See also Namespaces in XML 1.0 (Second Edition), [4] NCName.
bool QXmlName::isNull () const
Returns true if this QXmlName is not initialized with a valid combination of namespace URI, local name, and prefix.
A valid local name is always required. The prefix and namespace URI can be empty, but if the prefix is not empty, the namespace URI must not be empty. Local names and prefixes must be valid NCNames, e.g., abc.def or abc123.
QString QXmlName::localName ( const QXmlNamePool & namePool ) const
Returns the local name.
Note that for efficiency, the local name string is not stored in the QXmlName but in the QXmlNamePool that was passed to the constructor. Hence, that same namePool must be passed to this function, so it can be used for looking up the local name.
QString QXmlName::namespaceUri ( const QXmlNamePool & namePool ) const
Returns the namespace URI.
Note that for efficiency, the namespace URI string is not stored in the QXmlName but in the QXmlNamePool that was passed to the constructor. Hence, that same namePool must be passed to this function, so it can be used for looking up the namespace URI.
QString QXmlName::prefix ( const QXmlNamePool & namePool ) const
Returns the prefix.
Note that for efficiency, the prefix string is not stored in the QXmlName but in the QXmlNamePool that was passed to the constructor. Hence, that same namePool must be passed to this function, so it can be used for looking up the prefix.
QString QXmlName::toClarkName ( const QXmlNamePool & namePool ) const
Returns this QXmlName formatted as a Clark Name. For example, if the local name is html, the prefix is x, and the namespace URI is http:, then the Clark Name returned is:
{http:
If the local name is MyWidget and the namespace is empty, the Clark Name returned is:
MyWidget
Note that for efficiency, the namespace URI, local name, and prefix strings are not stored in the QXmlName but in the QXmlNamePool that was passed to the constructor. Hence, that same namePool must be passed to this function, so it can be used for looking up the three string components.
This function can be useful for debugging.
See also XML Namespaces, James Clark.
bool QXmlName::operator!= ( const QXmlName & other ) const
Returns true if this QXmlName is not equal to other; otherwise false. Two QXmlNames are equal if their namespace URIs are the same and their local names are the same. They are not equal if either their namespace URIs differ or their local names differ. Their prefixes are ignored.
Note that it is meaningless to compare two instances of QXmlName that were created with different name pools, but the attempt is not detected and the behavior is undefined.
See also operator==().
QXmlName & QXmlName::operator= ( const QXmlName & other )
Assigns other to this and returns this.
bool QXmlName::operator== ( const QXmlName & other ) const
Returns true if this QXmlName is equal to other; otherwise false. Two QXmlNames are equal if their namespace URIs are the same and their local names are the same. The prefixes are ignored.
Note that it is meaningless to compare two instances of QXmlName that were created with different name pools, but the attempt is not detected and the behavior is undefined.
See also operator!=().
Related Non-Members
uint qHash ( const QXmlName & name )
Computes a hash key from the the local name and the namespace URI in name. The prefix in name is not used in the computation.
This function was introduced in Qt 4.4.