Obsolete Members for QDomDocument

QDomDocument 类的以下成员已被废弃。提供这些成员是为了确保旧源代码能够继续运行。我们强烈建议不要在新代码中使用它们。

公共函数

(deprecated in 6.8) bool setContent(QIODevice *dev, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr)
(deprecated in 6.8) bool setContent(const QByteArray &buffer, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr)
(deprecated in 6.8) bool setContent(const QString &text, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr)
(deprecated in 6.8) bool setContent(QIODevice *dev, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr)
(deprecated in 6.8) bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr)
(deprecated in 6.8) bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr)
(deprecated in 6.8) bool setContent(const QString &text, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr)

成员函数文档

[deprecated in 6.8] bool QDomDocument::setContent(QIODevice *dev, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr)

自 6.8 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用返回 `ParseResult ` 的重载版本。

该函数从 IO 设备dev 读取 XML 文档,如果内容解析成功则返回 true;否则返回false 。

不会进行命名空间处理。

这是一个重载函数。

[deprecated in 6.8] bool QDomDocument::setContent(const QByteArray &buffer, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr)

自 6.8 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用返回 `ParseResult ` 的重载版本。

该函数从字节数组buffer 中读取 XML 文档,如果内容解析成功则返回 true;否则返回 false。

不会进行命名空间处理。

这是一个重载函数。

[deprecated in 6.8] bool QDomDocument::setContent(const QString &text, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr)

自 6.8 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用返回 `ParseResult ` 的重载版本。

该函数从字符串 `text` 中读取 XML 文档,如果内容解析成功则返回 `true`;否则返回 `false`。由于 `text ` 本身已经是 Unicode 字符串,因此不会进行编码检测。

也不会进行命名空间处理。

这是一个重载函数。

[deprecated in 6.8] bool QDomDocument::setContent(QIODevice *dev, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr)

自 6.8 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用接受 `ParseOptions ` 作为参数的重载版本。

该函数从 IO 设备dev 读取 XML 文档,如果内容解析成功则返回 true;否则返回false 。

注意: 如果dev 尚未打开,此 方法将尝试以只读模式打开它。在这种情况下,调用方负责调用 close。这一点将在 Qt 7 中发生变化,届时将不再打开dev 。因此,应用程序应在调用 setContent 之前自行打开该设备。

这是一个重载函数。

[deprecated in 6.8] bool QDomDocument::setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr)

自 6.8 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用接受ParseOptions 作为参数的重载版本。

该函数从QXmlStreamReader reader 读取 XML 文档并进行解析。如果内容解析成功,则返回true ;否则返回false 。

如果namespaceProcessing 为true ,解析器将识别 XML 文件中的命名空间,并将其前缀名、本地名和命名空间 URI 设置为相应值。如果namespaceProcessing 为false ,解析器在读取 XML 文件时不会进行命名空间处理。

如果发生解析错误,错误消息将保存在*errorMsg 中,行号保存在*errorLine 中,列号保存在*errorColumn 中(除非相关指针被设置为nullptr )。

这是一个重载函数。

另请参阅 QXmlStreamReader 。

[deprecated in 6.8] bool QDomDocument::setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr)

自 6.8 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用接受 `ParseOptions ` 作为参数的重载版本。

该函数从字节数组data 中解析 XML 文档,并将其设置为文档的内容。它会尝试根据 XML 规范的要求检测文档的编码。

如果namespaceProcessing 为 true,解析器将识别 XML 文件中的命名空间,并将前缀名、本地名和命名空间 URI 设置为适当的值。如果namespaceProcessing 为 false,解析器在读取 XML 文件时不会进行命名空间处理。

如果发生解析错误,该函数将返回false ,错误消息将存储在*errorMsg 中,行号存储在*errorLine 中,列号存储在*errorColumn 中(除非关联指针被设置为nullptr );否则该函数返回true 。

如果namespaceProcessing 为真,则函数QDomNode::prefix() 会为所有元素和属性返回一个字符串。如果元素或属性没有前缀,则返回空字符串。

仅由空白字符组成的文本节点将被移除,且不会出现在QDomDocument 中。

如果 `namespaceProcessing ` 为 false,则函数 `QDomNode::prefix()`、`QDomNode::localName()` 和 `QDomNode::namespaceURI()` 均返回空字符串。

实体引用按以下方式处理:

  • 内容中出现的对内部通用实体和字符实体的引用将被包含在内。结果是一个QDomText 节点,其中引用已被替换为相应的实体值。
  • 内部子集中出现的参数实体引用将被包含。结果是一个QDomDocumentType 节点,其中包含实体和符号声明,且引用已被替换为相应的实体值。
  • 任何未在内部子集中定义且出现在内容中的通用已解析实体引用,均表示为一个QDomEntityReference 节点。
  • 任何未在内部子集中定义且出现在内容之外的已解析实体引用,均被替换为空字符串。
  • 任何未解析的实体引用均被替换为空字符串。

这是一个重载函数。

另请参阅 QDomNode::namespaceURI()、QDomNode::localName()、QDomNode::prefix()、QString::isNull() 和QString::isEmpty()。

[deprecated in 6.8] bool QDomDocument::setContent(const QString &text, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr)

自 6.8 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用接受 `ParseOptions ` 作为参数的重载版本。

该函数从字符串text 中读取 XML 文档,如果内容解析成功则返回 true;否则返回false 。由于text 本身已是 Unicode 字符串,因此不会进行编码检测。

这是一个重载函数。

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