QXmlEntityResolver Class

QXmlEntityResolver 类提供了一个接口,用于解析 XML 数据中包含的外部实体。更多

Header: #include <QXmlEntityResolver>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
target_link_libraries(mytarget PRIVATE Qt6::Core5Compat)
qmake: QT += core5compat
继承于

QXmlDefaultHandler

注意:该类中的所有函数都是可重入的

公共函数

virtual ~QXmlEntityResolver()
virtual QString errorString() const = 0
virtual bool resolveEntity(const QString &publicId, const QString &systemId, QXmlInputSource *&ret) = 0

详细说明

如果应用程序需要实现对外部实体的自定义处理,则必须实现该接口,即resolveEntity() 并在QXmlReader::setEntityResolver() 中注册。

另请参见 QXmlDTDHandler,QXmlDeclHandler,QXmlContentHandler,QXmlErrorHandlerQXmlLexicalHandler

成员函数文档

[virtual noexcept] QXmlEntityResolver::~QXmlEntityResolver()

销毁实体解析器。

[pure virtual] QString QXmlEntityResolver::errorString() const

如果有处理函数返回false ,阅读器会调用该函数获取错误字符串。

[pure virtual] bool QXmlEntityResolver::resolveEntity(const QString &publicId, const QString &systemId, QXmlInputSource *&ret)

阅读器在打开任何外部实体(顶层文档实体除外)之前都会调用该函数。应用程序可以要求阅读器自己解析实体(ret 为 0),或者使用完全不同的输入源(ret 指向输入源)。

阅读器不再需要输入源ret 时,就会将其删除,因此应通过new 将其分配到堆上。

参数publicId 是外部实体的公共标识符,systemId 是外部实体的系统标识符,ret 是该函数的返回值。如果ret 为 0,则阅读器应自行解析该实体;如果为非 0,则必须指向阅读器使用的输入源。

如果该函数返回false ,则阅读器会停止解析并报错。阅读器使用函数errorString() 获取错误信息。

© 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.