Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QXmlName Class

TheQXmlName class represents the name of an XML node, in an efficient, namespace-aware way.More...

Header:#include <QXmlName>
Since: Qt 4.4

Note: All functions in this class arereentrant.

Public Functions

QXmlName()
QXmlName(QXmlNamePool & namePool, const QString & localName, const QString & namespaceURI = QString(), const QString & prefix = QString())
boolisNull() const
QStringlocalName(const QXmlNamePool & namePool) const
QStringnamespaceUri(const QXmlNamePool & namePool) const
QStringprefix(const QXmlNamePool & namePool) const
QStringtoClarkName(const QXmlNamePool & namePool) const
booloperator!=(const QXmlName & other) const
QXmlName &operator=(const QXmlName & other)
booloperator==(const QXmlName & other) const

Static Public Members

QXmlNamefromClarkName(const QString & clarkName, const QXmlNamePool & namePool)
boolisNCName(const QString & candidate)

Related Non-Members

uintqHash(const QXmlName & name)

Detailed Description

TheQXmlName class represents the name of an XML node, in an efficient, namespace-aware way.

QXmlName represents the name of an XML node in a way that is both efficient and safe for comparing names. Normally, an XML node represents an XML element or attribute, butQXmlName can also represent the names of other kinds of nodes, e.g.,QAbstractXmlReceiver::processingInstruction() andQAbstractXmlReceiver::namespaceBinding().

The name of an XML node has three components: Thenamespace URI, thelocal name, and theprefix. To see what these refer to in XML, consider the following snippet.

<book xmlns:dc='http://purl.org/dc/elements/1.1'      xmlns='http://example.com/MyDefault'>    <dc:title>Mobey Dick</dc:title> ...</book>

For the element namedbook,localName() returnsbook,namespaceUri() returnshttp://example.com/MyDefault, andprefix() returns an empty string. For the element namedtitle,localName() returnstitle,namespaceUri() returnshttp://purl.org/dc/elements/1.1, andprefix() returnsdc.

To ensure that operations withQXmlName are efficient, e.g., copying names and comparing them, each instance ofQXmlName is associated with aname pool, which must be specified atQXmlName construction time. The three components of theQXmlName, i.e., the namespace URI, the local name, and the prefix, are stored in the name pool mapped to identifiers so they can be shared. For this reason, the only way to create a valid instance ofQXmlName is to use the class constructor, where thename pool, local name, namespace URI, and prefix must all be specified.

Note thatQXmlName's default constructor constructs a null instance. It is typically used for allocating unused entries in collections ofQXmlName.

A side effect of associating each instance ofQXmlName with aname pool is that each instance ofQXmlName is tied to theQXmlNamePool with which it was created. However, theQXmlName class does not keep track of the name pool, so all the accessor functions, e.g.,namespaceUri(),prefix(),localName(), andtoClarkName() require that the correct name pool be passed to them. Failure to provide the correct name pool to these accessor functions results in undefined behavior.

Note that aname pool isnot an XML namespace. Onename pool can represent instances ofQXmlName from different XML namespaces, and the instances ofQXmlName from one XML namespace can be distributed over multiplename pools.

Comparing QXmlNames

To determine what aQXmlName refers to, thenamespace URI and thelocal name are used. Theprefix 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 prefixx, the two names compare equal as instances ofQXmlName, 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 validNCNames, e.g.,abc.def orabc123.

QXmlName represents what is sometimes called anexpanded QName, or simply a QName.

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

Member Function Documentation

QXmlName::QXmlName()

Constructs an uninitializedQXmlName. To build a validQXmlName, you normally use the other constructor, which takes aname pool, namespace URI, local name, and prefix as parameters. But you can also use this constructor to build a nullQXmlName and then assign an existingQXmlName to it.

See alsoisNull().

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

Constructs aQXmlName instance that insertslocalName,namespaceURI andprefix intonamePool if they aren't already there. The accessor functionsnamespaceUri(),prefix(),localName(), andtoClarkName() must be passed thenamePool used here, so thenamePool must remain in scope while the accessor functions might be used. However, two instances can be compared with== or!= and copied without thenamePool.

The user guarantees that the string components are valid for a QName. In particular, the local name, and the prefix (if present), must be validNCNames. The functionisNCName() 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 intonamePool.

[static]QXmlName QXmlName::fromClarkName(constQString & clarkName, constQXmlNamePool & namePool)

ConvertsclarkName into aQXmlName, inserts intonamePool, and returns it.

A clark name is a way to present a full QName with only one string, where the namespace cannot contain braces. Here are a couple of examples:

Clark NameDescription
htmlThe local namehtml, in no namespace
http://www.w3.org/1999/xhtmlhtmlThe local namehtml, in the XHTML namespace
http://www.w3.org/1999/xhtmlmy:htmlThe local namehtml, in the XHTML namespace, with the prefixmy

If the namespace contains braces, the returned value is either invalid or has undefined content.

IfclarkName is an invalid name, a default constructedQXmlName is returned.

This function was introduced in Qt 4.5.

See alsotoClarkName().

[static]bool QXmlName::isNCName(constQString & candidate)

Returns true ifcandidate is anNCName. AnNCName is a string that can be used as a name in XML andXQuery, e.g., the prefix or local name in an element or attribute, or the name of a variable.

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

bool QXmlName::isNull() const

Returns true if thisQXmlName is not initialized with a valid combination ofnamespace URI,local name, andprefix.

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 validNCNames, e.g.,abc.def orabc123.

QString QXmlName::localName(constQXmlNamePool & namePool) const

Returns the local name.

Note that for efficiency, the local name string is not stored in theQXmlName but in theQXmlNamePool that was passed to the constructor. Hence, that samenamePool must be passed to this function, so it can be used for looking up the local name.

QString QXmlName::namespaceUri(constQXmlNamePool & namePool) const

Returns the namespace URI.

Note that for efficiency, the namespace URI string is not stored in theQXmlName but in theQXmlNamePool that was passed to the constructor. Hence, that samenamePool must be passed to this function, so it can be used for looking up the namespace URI.

QString QXmlName::prefix(constQXmlNamePool & namePool) const

Returns the prefix.

Note that for efficiency, the prefix string is not stored in theQXmlName but in theQXmlNamePool that was passed to the constructor. Hence, that samenamePool must be passed to this function, so it can be used for looking up the prefix.

QString QXmlName::toClarkName(constQXmlNamePool & namePool) const

Returns thisQXmlName formatted as a Clark Name. For example, if the local name ishtml, the prefix isx, and the namespace URI ishttp://www.w3.org/1999/xhtml/, then the Clark Name returned is:

{http://www.w3.org/1999/xhtml/}x:html.

If the local name isMyWidget 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 theQXmlName but in theQXmlNamePool that was passed to the constructor. Hence, that samenamePool 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 alsoXML Namespaces, James Clark andfromClarkName().

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

Returns true if thisQXmlName isnot equal toother; otherwise false. Two QXmlNames are equal if their namespace URIs are the sameand 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 ofQXmlName that were created with differentname pools, but the attempt is not detected and the behavior is undefined.

See alsooperator==().

QXmlName & QXmlName::operator=(constQXmlName & other)

Assignsother tothis and returnsthis.

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

Returns true if thisQXmlName is equal toother; otherwise false. Two QXmlNames are equal if their namespace URIs are the sameand their local names are the same. The prefixes are ignored.

Note that it is meaningless to compare two instances ofQXmlName that were created with differentname pools, but the attempt is not detected and the behavior is undefined.

See alsooperator!=().

Related Non-Members

uintqHash(constQXmlName & name)

Computes a hash key from the local name and the namespace URI inname. The prefix inname is not used in the computation.

This function was introduced in Qt 4.4.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp