QXmlNameclass represents the name of an XML node, in an efficient, namespace-aware way.QXmlNamerepresents 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, butQXmlNamecan also represent the names of other kinds of nodes, e.g.,processingInstruction()andnamespaceBinding(). 更多 …
def
__eq__
(other)
def
__ne__
(other)
def
isNull
()
def
localName
(query)
def
namespaceUri
(query)
def
prefix
(query)
def
toClarkName
(query)
def
fromClarkName
(clarkName, namePool)
def
isNCName
(candidate)
The name of an XML node has three components: The namespace URI , local name ,和 prefix . To see what these refer to in XML, consider the following snippet.
<Code snippet "/tmp/snapshot-qt5full-5.15.0/qt5/qtbase/patternist/mobeyDick.xml" not found>For the element named book ,
localName()返回 book ,namespaceUri()返回 http://example.com/MyDefault ,和prefix()returns an empty string. For the element named title ,localName()返回 title ,namespaceUri()返回 http://purl.org/dc/elements/1.1 ,和prefix()返回 dc .To ensure that operations with
QXmlNameare efficient, e.g., copying names and comparing them, each instance ofQXmlNameis associated with aname pool, which must be specified atQXmlNameconstruction 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 ofQXmlNameis to use the class constructor, where thename pool, local name, namespace URI, and prefix must all be specified.注意:
QXmlName‘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 of
QXmlName采用name poolis that each instance ofQXmlNameis tied to theQXmlNamePoolwith which it was created. However, theQXmlNameclass does not keep track of the name pool, so all the accessor functions, e.g.,namespaceUri(),prefix(),localName(),和toClarkName()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.注意:
name poolis not an XML namespace. Onename poolcan represent instances ofQXmlNamefrom different XML namespaces, and the instances ofQXmlNamefrom one XML namespace can be distributed over multiplename pools.
To determine what a
QXmlNamerefers to, the namespace URI 和 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.<Code snippet "/tmp/snapshot-qt5full-5.15.0/qt5/qtbase/patternist/svgDocumentElement.xml" not found><Code snippet "/tmp/snapshot-qt5full-5.15.0/qt5/qtbase/patternist/xsvgDocumentElement.xml" not found>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 .
QXmlNamerepresents what is sometimes called an expanded QName , or simply a QName.
QXmlName
¶
QXmlName(namePool, localName[, namespaceURI=””[, prefix=””]])
QXmlName(other)
- param namespaceURI
unicode
- param prefix
unicode
- param namePool
- param other
- param localName
unicode
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
到它。
另请参阅
构造
QXmlName
instance that inserts
localName
,
namespaceURI
and
prefix
into
namePool
if they aren’t already there. The accessor functions
namespaceUri()
,
prefix()
,
localName()
,和
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.
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
.
PySide2.QtXmlPatterns.QXmlName.
常量
¶
Various constants used in the QPatternist::NamePool and
QXmlName
.
Setting of the mask enums use essentially this:
<Code snippet "/tmp/snapshot-qt5full-5.15.0/qt5/qtbase/code/src_xmlpatterns_api_qxmlname.cpp" not found>
The masks, such as , are positive. That is, for the area which the name resides, the bits are set.
PySide2.QtXmlPatterns.QXmlName.
fromClarkName
(
clarkName
,
namePool
)
¶
clarkName – unicode
namePool
–
QXmlNamePool
转换
clarkName
成
QXmlName
, inserts into
namePool
, 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 Name |
描述 |
|
|
The local name
|
|
|
The local name
|
|
|
The local name
|
If the namespace contains braces, the returned value is either invalid or has undefined content.
若
clarkName
is an invalid name, a default constructed
QXmlName
被返回。
另请参阅
PySide2.QtXmlPatterns.QXmlName.
isNCName
(
candidate
)
¶
candidate – unicode
bool
返回 true 若
candidate
是
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.
PySide2.QtXmlPatterns.QXmlName.
isNull
(
)
¶
bool
返回 true,若此
QXmlName
is not initialized with a valid combination of
namespace URI
,
local name
,和
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 .
PySide2.QtXmlPatterns.QXmlName.
localName
(
query
)
¶
query
–
QXmlNamePool
unicode
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.
PySide2.QtXmlPatterns.QXmlName.
namespaceUri
(
query
)
¶
query
–
QXmlNamePool
unicode
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.
PySide2.QtXmlPatterns.QXmlName.
__ne__
(
other
)
¶
other
–
QXmlName
bool
返回 true,若此
QXmlName
is
not
等于
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.
另请参阅
operator==()
PySide2.QtXmlPatterns.QXmlName.
__eq__
(
other
)
¶
other
–
QXmlName
bool
返回 true,若此
QXmlName
等于
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.
另请参阅
operator!=()
PySide2.QtXmlPatterns.QXmlName.
prefix
(
query
)
¶
query
–
QXmlNamePool
unicode
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.
PySide2.QtXmlPatterns.QXmlName.
toClarkName
(
query
)
¶
query
–
QXmlNamePool
unicode
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://www.w3.org/1999/xhtml/
, then the Clark Name returned is:
{http://www.w3.org/1999/xhtml/}x:html.
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.