QDomProcessingInstruction Class
QDomProcessingInstruction 类表示一个 XML 处理指令。更多内容...
| 头文件: | #include <QDomProcessingInstruction> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Xml) target_link_libraries(mytarget PRIVATE Qt6::Xml) |
| qmake: | QT += xml |
| 继承自: | QDomNode |
- 所有成员列表(包括继承的成员)
- QDomProcessingInstruction 属于XML 类。
注意:该类中的所有函数均为可重入的。
公共函数
| QDomProcessingInstruction() | |
| QDomProcessingInstruction(const QDomProcessingInstruction &processingInstruction) | |
| QString | data() const |
| QDomNode::NodeType | nodeType() const |
| void | setData(const QString &data) |
| QString | target() const |
| QDomProcessingInstruction & | operator=(const QDomProcessingInstruction &other) |
详细说明
XML 中使用处理指令来在文档文本中保存与处理器相关的信息。
出现在 XML 文档顶部的 XML 声明(通常为<?xml version='1.0' encoding='UTF-8'?> )会被 QDom 视为处理指令。这很遗憾,因为 XML 声明并不是处理指令;除其他区别外,它只能插入在文档的第一行,而不能插入在文档的任何其他位置。
注意:请 勿使用此函数来创建 XML 声明。尽管 XML 声明与处理指令具有相同的语法,但它并不是处理指令。 根据《XML 1.0 规范》和W3C DOM 结构模型,XML 声明是文档前言的一部分,不属于 DOM 树——这意味着它不应作为 DOM 节点表示,也不能通过 DOM API 创建或插入。 如果您需要生成包含 XML 声明的结构良好的 XML 文档,请使用QXmlStreamWriter ,该方法通过writeStartDocument 提供了对编写声明的正确支持。
处理指令的内容可通过data() 获取,并通过setData() 设置。处理指令的目标可通过target() 获取。
有关文档对象模型(DOM)的更多信息,请参阅第 1 级 和 第 2 级核心规范。有关 DOM 实现的更通用的介绍,请参阅QDomDocument 文档。
成员函数文档
QDomProcessingInstruction::QDomProcessingInstruction()
构建一个空的处理指令。使用QDomDocument::createProcessingInstruction() 来创建一个带有内容的处理指令。
QDomProcessingInstruction::QDomProcessingInstruction(const QDomProcessingInstruction &processingInstruction)
创建processingInstruction 的副本。
该副本的数据是共享的(浅拷贝):修改其中一个节点也会改变另一个节点。若要进行深拷贝,请使用cloneNode()。
QString QDomProcessingInstruction::data() const
返回此处理指令的内容。
QDomNode::NodeType QDomProcessingInstruction::nodeType() const
返回ProcessingInstructionNode 。
void QDomProcessingInstruction::setData(const QString &data)
将处理指令中包含的数据设置为data 。
另请参阅 data()。
QString QDomProcessingInstruction::target() const
返回此处理指令的目标。
另请参阅 data()。
QDomProcessingInstruction &QDomProcessingInstruction::operator=(const QDomProcessingInstruction &other)
将other 分配给此处理指令。
该复制的数据是共享的(浅拷贝):修改一个节点也会改变另一个节点。若要进行深拷贝,请使用cloneNode()。
© 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.