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 XML 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

如果namespaceProcessingtrue ,解析器会识别 XML 文件中的命名空间,并将前缀名、本地名和命名空间 URI 设置为适当的值。如果namespaceProcessingfalse ,解析器在读取 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 为假,解析器在读取 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 字符串,因此不进行编码检测。

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