QXmlNamespaceSupport Class
QXmlNamespaceSupport 类是希望包含命名空间支持的 XML 阅读器的辅助类。更多
Header: | #include <QXmlNamespaceSupport> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core5Compat) target_link_libraries(mytarget PRIVATE Qt6::Core5Compat) |
qmake: | QT += core5compat |
注意:该类中的所有函数都是可重入的。
公共函数
QXmlNamespaceSupport() | |
~QXmlNamespaceSupport() | |
void | popContext() |
QString | prefix(const QString &uri) const |
QStringList | prefixes() const |
QStringList | prefixes(const QString &uri) const |
void | processName(const QString &qname, bool isAttribute, QString &nsuri, QString &localname) const |
void | pushContext() |
void | reset() |
void | setPrefix(const QString &pre, const QString &uri) |
void | splitName(const QString &qname, QString &prefix, QString &localname) const |
QString | uri(const QString &prefix) const |
详细说明
您可以使用setPrefix() 设置当前命名空间的前缀,并使用prefixes() 获取当前前缀(或给定 URI 的前缀)列表。命名空间 URI 可通过uri() 获取。使用pushContext() 可以启动一个新的命名空间上下文,使用popContext() 可以返回到以前的命名空间上下文。使用splitName() 或processName() 可以将名称拆分为前缀和本地名称。
成员函数文档
QXmlNamespaceSupport::QXmlNamespaceSupport()
构造一个 QXmlNamespaceSupport。
[noexcept]
QXmlNamespaceSupport::~QXmlNamespaceSupport()
void QXmlNamespaceSupport::popContext()
恢复到之前的命名空间上下文。
通常,应在每个 XML 元素的末尾弹出上下文。弹出上下文后,以前有效的所有名称空间前缀映射都将恢复。
另请参见 pushContext()。
QString QXmlNamespaceSupport::prefix(const QString &uri) const
返回映射到名称空间 URIuri 的前缀之一。
如果当前有一个以上的前缀映射到同一个 URI,该函数将进行任意选择;如果需要所有前缀,请使用prefixes() 代替。
注意:要检查默认前缀,请使用uri() 函数,参数为""。
另请参见 setPrefix()。
QStringList QXmlNamespaceSupport::prefixes() const
返回当前声明的所有前缀的列表。
如果存在默认前缀,该函数不会在列表中返回;请使用uri() 检查默认前缀,参数为""。
QStringList QXmlNamespaceSupport::prefixes(const QString &uri) const
这是一个重载函数。
返回当前为名称空间 URIuri 声明的所有前缀的列表。
其中包括 "xml: "前缀。如果您只想要一个映射到命名空间 URI 的前缀,并且不在乎得到的是哪一个,请使用prefix() 函数。
注意:空(默认)前缀从不包含在此列表中;要检查是否存在默认名称空间,请调用uri() 并将""作为参数。
void QXmlNamespaceSupport::processName(const QString &qname, bool isAttribute, QString &nsuri, QString &localname) const
删除前缀并在当前声明的前缀中查找,从而处理当前上下文中的原始 XML 1.0 名称。
qname 是要处理的原始 XML 1.0 名称。如果该名称是属性名称,则 为 true。isAttribute
该函数将命名空间 URI 保存在nsuri 中(如果原始名称有未声明的前缀,则将其设置为空字符串),并将本地名称(不含前缀)保存在localname 中(如果没有使用命名空间,则将其设置为空字符串)。
需要注意的是,属性名的处理方式与元素名不同:未加前缀的元素名会获得默认命名空间(如果有的话),而未加前缀的属性名则不会。
void QXmlNamespaceSupport::pushContext()
启动一个新的命名空间上下文。
通常情况下,您应该在每个 XML 元素的开头推送一个新上下文:新上下文会自动继承其父上下文的声明,而且还会跟踪在此上下文中进行了哪些声明。
另请参见 popContext()。
void QXmlNamespaceSupport::reset()
重置该命名空间支持对象,以备再次使用。
void QXmlNamespaceSupport::setPrefix(const QString &pre, const QString &uri)
此函数将当前命名空间上下文中的前缀pre 声明为命名空间 URIuri 。除非该前缀在后代上下文中被阴影覆盖,否则该前缀将一直有效,直至该上下文被弹出。
请注意,该库中有一个不对称的地方。prefix() 不会返回默认的""前缀,即使您已声明了默认前缀;要检查默认前缀,必须使用uri() 明确查找。这种不对称的存在是为了方便查找不允许使用默认前缀的属性名称的前缀。
另请参见 prefix()。
void QXmlNamespaceSupport::splitName(const QString &qname, QString &prefix, QString &localname) const
在": "处分割qname 名称,并返回prefix 中的前缀和localname 中的本地名称。
另请参见 processName()。
QString QXmlNamespaceSupport::uri(const QString &prefix) const
查找当前上下文中的前缀prefix ,并返回当前映射的命名空间 URI。默认名称空间使用空字符串("")。
© 2025 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 the GNU 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.