QDomNode 类

QDomNode class is the base class for all the nodes in a DOM tree. 更多...

头: #include <QDomNode>
qmake: QT += xml
继承者:

QDomAttr , QDomCharacterData , QDomDocument , QDomDocumentFragment , QDomDocumentType , QDomElement , QDomEntity , QDomEntityReference , QDomNotation ,和 QDomProcessingInstruction

注意: 此类的所有函数 可重入 .

公共类型

enum EncodingPolicy { EncodingFromDocument, EncodingFromTextStream }
enum NodeType { ElementNode, AttributeNode, TextNode, CDATASectionNode, ..., CharacterDataNode }

公共函数

QDomNode ()
QDomNode (const QDomNode & n )
~QDomNode ()
QDomNode appendChild (const QDomNode & newChild )
QDomNamedNodeMap attributes () const
QDomNodeList childNodes () const
void clear ()
QDomNode cloneNode (bool deep = true) const
int columnNumber () const
QDomNode firstChild () const
QDomElement firstChildElement (const QString & tagName = QString()) const
bool hasAttributes () const
bool hasChildNodes () const
QDomNode insertAfter (const QDomNode & newChild , const QDomNode & refChild )
QDomNode insertBefore (const QDomNode & newChild , const QDomNode & refChild )
bool isAttr () const
bool isCDATASection () const
bool isCharacterData () const
bool isComment () const
bool isDocument () const
bool isDocumentFragment () const
bool isDocumentType () const
bool isElement () const
bool isEntity () const
bool isEntityReference () const
bool isNotation () const
bool isNull () const
bool isProcessingInstruction () const
bool isSupported (const QString & feature , const QString & version ) const
bool isText () const
QDomNode lastChild () const
QDomElement lastChildElement (const QString & tagName = QString()) const
int lineNumber () const
QString localName () const
QDomNode namedItem (const QString & name ) const
QString namespaceURI () const
QDomNode nextSibling () const
QDomElement nextSiblingElement (const QString & tagName = QString()) const
QString nodeName () const
NodeType nodeType () const
QString nodeValue () const
void normalize ()
QDomDocument ownerDocument () const
QDomNode parentNode () const
QString prefix () const
QDomNode previousSibling () const
QDomElement previousSiblingElement (const QString & tagName = QString()) const
QDomNode removeChild (const QDomNode & oldChild )
QDomNode replaceChild (const QDomNode & newChild , const QDomNode & oldChild )
void save (QTextStream & stream , int indent , EncodingPolicy encodingPolicy = QDomNode::EncodingFromDocument) const
void setNodeValue (const QString & v )
void setPrefix (const QString & pre )
QDomAttr toAttr () const
QDomCDATASection toCDATASection () const
QDomCharacterData toCharacterData () const
QDomComment toComment () const
QDomDocument toDocument () const
QDomDocumentFragment toDocumentFragment () const
QDomDocumentType toDocumentType () const
QDomElement toElement () const
QDomEntity toEntity () const
QDomEntityReference toEntityReference () const
QDomNotation toNotation () const
QDomProcessingInstruction toProcessingInstruction () const
QDomText toText () const
bool operator!= (const QDomNode & n ) const
QDomNode & operator= (const QDomNode & n )
bool operator== (const QDomNode & n ) const
QTextStream & operator<< (QTextStream & str , const QDomNode & node )

详细描述

QDomNode class is the base class for all the nodes in a DOM tree.

Many functions in the DOM return a QDomNode .

可以找出节点的类型使用 isAttr (), isCDATASection (), isDocumentFragment (), isDocument (), isDocumentType (), isElement (), isEntityReference (), isText (), isEntity (), isNotation (), isProcessingInstruction (), isCharacterData () 和 isComment ().

A QDomNode can be converted into one of its subclasses using toAttr (), toCDATASection (), toDocumentFragment (), toDocument (), toDocumentType (), toElement (), toEntityReference (), toText (), toEntity (), toNotation (), toProcessingInstruction (), toCharacterData () 或 toComment ()。可以将节点转换为 null 节点采用 clear ().

Copies of the QDomNode class share their data using explicit sharing. This means that modifying one node will change all copies. This is especially useful in combination with functions which return a QDomNode ,如 firstChild ()。可以制作节点的独立 (深) 副本采用 cloneNode ().

A QDomNode can be null, much like a null pointer. Creating a copy of a null node results in another null node. It is not possible to modify a null node, but it is possible to assign another, possibly non-null node to it. In this case, the copy of the null node will remain null. You can check if a QDomNode is null by calling isNull (). The empty constructor of a QDomNode (or any of the derived classes) creates a null node.

插入节点采用 insertBefore (), insertAfter () 或 appendChild ()。可以采用另一节点替换某个节点使用 replaceChild () 和移除节点采用 removeChild ().

要遍历节点使用 firstChild () 以获取节点的第一子级 (若有的话),和 nextSibling () to traverse. QDomNode also provides lastChild (), previousSibling () 和 parentNode ()。要查找具有特定节点名称的第一子级节点使用 namedItem ().

要找出节点是否拥有子级使用 hasChildNodes () 和要获取节点的所有子级的列表使用 childNodes ().

节点名称和值 (其含义因类型而异) 的返回通过 nodeName () 和 nodeValue () 分别。节点类型的返回通过 nodeType ()。可以设置节点的值采用 setNodeValue ().

节点所属文档的返回通过 ownerDocument ().

相邻 QDomText 节点可以合并成单个节点采用 normalize ().

QDomElement 可以检索节点拥有的属性采用 attributes ().

QDomElement and QDomAttr 节点可以拥有可以检索的名称空间采用 namespaceURI ()。它们的本地名称的检索采用 localName (),和它们的前缀采用 prefix ()。可以设置前缀采用 setPrefix ().

可以将节点的 XML 表示写入文本流采用 save ().

以下范例查找 XML 文档第一元素并打印其直接子级所有元素的名称。

QDomDocument d;
d.setContent(someXML);
QDomNode n = d.firstChild();
while (!n.isNull()) {
    if (n.isElement()) {
        QDomElement e = n.toElement();
        cout << "Element name: " << e.tagName() << endl;
        break;
    }
    n = n.nextSibling();
}
					

有关文档对象模型的进一步信息,见 级别 1 and 级别 2 核心 。有关 DOM 实现的更一般介绍,见 QDomDocument 文档编制。

成员类型文档编制

enum QDomNode:: EncodingPolicy

此枚举指定如何 QDomNode::save () 确定要使用什么编码当序列化时。

常量 描述
QDomNode::EncodingFromDocument 1 编码抓取自文档。
QDomNode::EncodingFromTextStream 2 编码抓取自 QTextStream .

该枚举在 Qt 4.3 引入或被修改。

另请参阅 QDomNode::save ().

enum QDomNode:: NodeType

此枚举定义节点的类型:

常量 描述
QDomNode::ElementNode 1
QDomNode::AttributeNode 2
QDomNode::TextNode 3
QDomNode::CDATASectionNode 4
QDomNode::EntityReferenceNode 5
QDomNode::EntityNode 6
QDomNode::ProcessingInstructionNode 7
QDomNode::CommentNode 8
QDomNode::DocumentNode 9
QDomNode::DocumentTypeNode 10
QDomNode::DocumentFragmentNode 11
QDomNode::NotationNode 12
QDomNode::BaseNode 21 QDomNode 对象,即不是 QDomNode 子类。
QDomNode::CharacterDataNode 22

成员函数文档编制

QDomNode:: QDomNode ()

构造 null 节点。

QDomNode:: QDomNode (const QDomNode & n )

构造副本为 n .

拷贝数据是共享的 (浅拷贝):修改一个节点也将改变另一节点。若想要制作深度副本,使用 cloneNode ().

QDomNode:: ~QDomNode ()

销毁对象并释放其资源。

QDomNode QDomNode:: appendChild (const QDomNode & newChild )

追加 newChild 作为节点的最后子级。

newChild 是另一节点的子级,它会重设父级到此节点。若 newChild 是此节点的子级,那么它在子级列表中的位置会改变。

newChild QDomDocumentFragment ,那么片段的子级将从片段中移除并追加。

newChild QDomElement 和此节点是 QDomDocument ,已经拥有的元素节点将作为子级, newChild 不添加作为子级并返回 null 节点。

返回新的引用为 newChild 当成功时或 null 节点 当故障时。

在 null 节点 (例如:采用默认构造函数创建) 调用此函数什么都不做并返回 null 节点 .

DOM 规范禁止插入属性节点,但由于历史原因,无论如何 QDom 接受它们。

另请参阅 insertBefore (), insertAfter (), replaceChild (),和 removeChild ().

QDomNamedNodeMap QDomNode:: attributes () const

返回所有属性的命名节点映射。才提供属性对于 QDomElement s.

改变映射中的属性也会改变其属性对于此 QDomNode .

QDomNodeList QDomNode:: childNodes () const

返回所有直接子级节点的列表。

大多数情况下,会调用此函数在 QDomElement 对象。

例如,若 XML 文档看起来像这样:

<body>
<h1>Heading</h1>
<p>Hello <b>you</b></p>
</body>
					

那么 body 元素的子级节点列表将包含由 <h1> 和 <p> 标签创建的节点。

列表中的节点不是副本;因此改变列表中的节点也会改变此节点的子级。

另请参阅 firstChild () 和 lastChild ().

void QDomNode:: clear ()

将节点转换为 null 节点;若它之前不是 null 节点,删除其类型和内容。

另请参阅 isNull ().

QDomNode QDomNode:: cloneNode ( bool deep = true) const

创建深 (非浅) 副本为 QDomNode .

deep 为 true,那么会递归完成克隆,意味着所有节点的子级也被深拷贝。若 deep 为 false 仅节点本身被拷贝且副本没有子级节点。

int QDomNode:: columnNumber () const

对于创建的节点通过 QDomDocument::setContent (),此函数返回经剖析 XML 文档节点的列数。否则,返回 -1。

该函数在 Qt 4.1 引入。

另请参阅 lineNumber () 和 QDomDocument::setContent ().

QDomNode QDomNode:: firstChild () const

返回节点的第一子级。若没有子级节点, null 节点 被返回。改变返回节点也会改变文档树节点。

另请参阅 lastChild () 和 childNodes ().

QDomElement QDomNode:: firstChildElement (const QString & tagName = QString()) const

返回的第一子级元素具有标签名称 tagName 若 tagName 非空; 否则返回第一子级元素。返回 null 元素若不存在这样的子级。

另请参阅 lastChildElement (), previousSiblingElement (),和 nextSiblingElement ().

bool QDomNode:: hasAttributes () const

返回 true 若节点拥有属性;否则返回 false .

另请参阅 attributes ().

bool QDomNode:: hasChildNodes () const

返回 true 若节点拥有一个或多个子级;否则返回 false .

QDomNode QDomNode:: insertAfter (const QDomNode & newChild , const QDomNode & refChild )

插入节点 newChild 后于子级节点 refChild . refChild 必须是此节点的直接子级。若 refChild is null then newChild 被追加作为此节点的最后子级。

newChild 是另一节点的子级,它会重设父级到此节点。若 newChild 是此节点的子级,那么它在子级列表中的位置会改变。

newChild QDomDocumentFragment ,那么片段的子级将从片段被移除并插入后于 refChild .

返回新的引用为 newChild 当成功时或 null 节点 当故障时。

DOM 规范禁止插入属性节点,但由于历史原因 QDom 仍然接受它们。

另请参阅 insertBefore (), replaceChild (), removeChild (),和 appendChild ().

QDomNode QDomNode:: insertBefore (const QDomNode & newChild , const QDomNode & refChild )

插入节点 newChild 前于子级节点 refChild . refChild 必须是此节点的直接子级。若 refChild is null then newChild 被插入作为节点的第一子级。

newChild 是另一节点的子级,它会重设父级到此节点。若 newChild 是此节点的子级,那么它在子级列表中的位置会改变。

newChild QDomDocumentFragment ,那么片段的子级将从片段被移除并插入前于 refChild .

返回新的引用为 newChild 当成功时或 null 节点 当故障时。

DOM 规范禁止插入属性节点,但由于历史原因 QDom 仍然接受它们。

另请参阅 insertAfter (), replaceChild (), removeChild (),和 appendChild ().

bool QDomNode:: isAttr () const

返回 true 若节点是属性;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomAttribute;可以采用 toAttribute() 获取 QDomAttribute。

另请参阅 toAttr ().

bool QDomNode:: isCDATASection () const

返回 true 若节点是 CDATA 区间;否则返回 false。

若此函数返回 true ,它并未暗示此对象是 QDomCDATASection ;可以获取 QDomCDATASection with toCDATASection ().

另请参阅 toCDATASection ().

bool QDomNode:: isCharacterData () const

返回 true 若节点是字符数据节点;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomCharacterData ;可以获取 QDomCharacterData with toCharacterData ().

另请参阅 toCharacterData ().

bool QDomNode:: isComment () const

返回 true 若节点是注释;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomComment ;可以获取 QDomComment with toComment ().

另请参阅 toComment ().

bool QDomNode:: isDocument () const

返回 true 若节点是文档;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomDocument ;可以获取 QDomDocument with toDocument ().

另请参阅 toDocument ().

bool QDomNode:: isDocumentFragment () const

返回 true 若节点是文档片段;否则返回 false。

若此函数返回 true ,它并未暗示此对象是 QDomDocumentFragment ;可以获取 QDomDocumentFragment with toDocumentFragment ().

另请参阅 toDocumentFragment ().

bool QDomNode:: isDocumentType () const

返回 true 若节点是文档类型;否则返回 false。

若此函数返回 true ,它并未暗示此对象是 QDomDocumentType ;可以获取 QDomDocumentType with toDocumentType ().

另请参阅 toDocumentType ().

bool QDomNode:: isElement () const

返回 true 若节点是元素;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomElement ;可以获取 QDomElement with toElement ().

另请参阅 toElement ().

bool QDomNode:: isEntity () const

返回 true 若节点是实体;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomEntity ;可以获取 QDomEntity with toEntity ().

另请参阅 toEntity ().

bool QDomNode:: isEntityReference () const

返回 true 若节点是实体引用;否则返回 false。

若此函数返回 true ,它并未暗示此对象是 QDomEntityReference ;可以获取 QDomEntityReference with toEntityReference ().

另请参阅 toEntityReference ().

bool QDomNode:: isNotation () const

返回 true 若节点是表示法;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomNotation ;可以获取 QDomNotation with toNotation ().

另请参阅 toNotation ().

bool QDomNode:: isNull () const

返回 true 若此节点为 null (即:若它没有类型或内容);否则返回 false .

bool QDomNode:: isProcessingInstruction () const

返回 true 若节点是处理指令;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomProcessingInstruction ;可以获取 QProcessingInstruction 采用 toProcessingInstruction ().

另请参阅 toProcessingInstruction ().

bool QDomNode:: isSupported (const QString & feature , const QString & version ) const

返回 true 若 DOM (文档对象模型) 实现实现特征 feature 且此特征由此节点支持在版本 version ;否则返回 false .

另请参阅 QDomImplementation::hasFeature ().

bool QDomNode:: isText () const

返回 true 若节点是文本节点;否则返回 false .

若此函数返回 true ,它并未暗示此对象是 QDomText ;可以获取 QDomText with toText ().

另请参阅 toText ().

QDomNode QDomNode:: lastChild () const

返回节点的最后子级。若没有子级节点, null 节点 被返回。改变返回节点也会改变文档树节点。

另请参阅 firstChild () 和 childNodes ().

QDomElement QDomNode:: lastChildElement (const QString & tagName = QString()) const

返回的最后子级元素具有标签名称 tagName 若 tagName 非空;否则返回最后子级元素。返回 null 元素,若不存在这种子级。

另请参阅 firstChildElement (), previousSiblingElement (),和 nextSiblingElement ().

int QDomNode:: lineNumber () const

对于创建的节点通过 QDomDocument::setContent (),此函数返回剖析节点的 XML 文档行号。否则,返回 -1。

该函数在 Qt 4.1 引入。

另请参阅 columnNumber () 和 QDomDocument::setContent ().

QString QDomNode:: localName () const

若节点使用名称空间,此函数返回节点的本地名称;否则它返回空字符串。

仅节点为类型 ElementNode or AttributeNode 可以拥有名称空间。名称空间必须在创建时指定;之后添加名称空间不可能。

另请参阅 prefix (), namespaceURI (), QDomDocument::createElementNS (),和 QDomDocument::createAttributeNS ().

QDomNode QDomNode:: namedItem (const QString & name ) const

返回第一直接子级节点对于其 nodeName () 等于 name .

若不存在这种直接子级, null 节点 被返回。

另请参阅 nodeName ().

QString QDomNode:: namespaceURI () const

返回此节点的名称空间 URI 或空字符串,若节点没有名称空间 URI。

仅节点为类型 ElementNode or AttributeNode 可以拥有名称空间。名称空间 URI 必须在创建时指定且以后不能更改。

另请参阅 prefix (), localName (), QDomDocument::createElementNS (),和 QDomDocument::createAttributeNS ().

QDomNode QDomNode:: nextSibling () const

返回文档树中的下一同级。改变返回节点还会改变文档树中的节点。

若拥有的 XML 像这样:

<h1>Heading</h1>
<p>The text...</p>
<h2>Next heading</h2>
					

和此 QDomNode 表示 <p> 标签,nextSibling() 将返回 <h2> 标签表示节点。

另请参阅 previousSibling ().

QDomElement QDomNode:: nextSiblingElement (const QString & tagName = QString()) const

返回的下一同级元素具有标签名称 tagName if tagName 非空;否则返回任何下一同级元素。返回 null 元素,若不存在这种同级。

另请参阅 firstChildElement (), previousSiblingElement (),和 lastChildElement ().

QString QDomNode:: nodeName () const

返回节点的名称。

名称的含义从属子类:

Name 含义
QDomAttr 属性名称
QDomCDATASection 字符串 "#cdata-section"
QDomComment 字符串 "#comment"
QDomDocument 字符串 "#document"
QDomDocumentFragment 字符串 "#document-fragment"
QDomDocumentType 文件类型的名称
QDomElement 标签名称
QDomEntity 实体名称
QDomEntityReference 引用实体的名称
QDomNotation 表示法名称
QDomProcessingInstruction 处理指令的目标
QDomText 字符串 "#text"

注意: This function does not take the presence of namespaces into account when processing the names of element and attribute nodes. As a result, the returned name can contain any namespace prefix that may be present. To obtain the node name of an element or attribute, use localName (); to obtain the namespace prefix, use namespaceURI ().

另请参阅 nodeValue ().

NodeType QDomNode:: nodeType () const

返回节点的类型。

另请参阅 toAttr (), toCDATASection (), toDocumentFragment (), toDocument (), toDocumentType (), toElement (), toEntityReference (), toText (), toEntity (), toNotation (), toProcessingInstruction (), toCharacterData (),和 toComment ().

QString QDomNode:: nodeValue () const

返回节点的值。

值的含义从属子类:

Name 含义
QDomAttr 属性值
QDomCDATASection CDATA 区间的内容
QDomComment 注释
QDomProcessingInstruction 处理指令的数据
QDomText 文本

All the other subclasses do not have a node value and will return an empty string.

另请参阅 setNodeValue () 和 nodeName ().

void QDomNode:: normalize ()

Calling normalize() on an element converts all its children into a standard form. This means that adjacent QDomText objects will be merged into a single text object ( QDomCDATASection nodes are not merged).

QDomDocument QDomNode:: ownerDocument () const

返回此节点所属的文档。

QDomNode QDomNode:: parentNode () const

返回父级节点。若此节点没有父级,返回 null 节点 (即:节点的 isNull () 返回 true ).

QString QDomNode:: prefix () const

返回节点名称空间前缀,或空字符串若节点没有名称空间前缀。

仅节点为类型 ElementNode or AttributeNode 可以拥有名称空间。必须在创建时指定名称空间前缀。若节点是采用名称空间前缀创建的,可以稍后改变它采用 setPrefix ().

如果创建元素或属性采用 QDomDocument::createElement () 或 QDomDocument::createAttribute (),前缀将是空字符串。若使用 QDomDocument::createElementNS () 或 QDomDocument::createAttributeNS () 代替,前缀不会是空字符串;但它可能是空字符串,若名称尚未拥有前缀。

另请参阅 setPrefix (), localName (), namespaceURI (), QDomDocument::createElementNS (),和 QDomDocument::createAttributeNS ().

QDomNode QDomNode:: previousSibling () const

返回文档树的上一同级。改变返回节点也会改变文档树节点。

例如,若拥有的 XML 像这样:

<h1>Heading</h1>
<p>The text...</p>
<h2>Next heading</h2>
					

和此 QDomNode 表示 <p> 标签,previousSibling() 将返回 <h1> 标签表示节点。

另请参阅 nextSibling ().

QDomElement QDomNode:: previousSiblingElement (const QString & tagName = QString()) const

返回的上一同级元素具有标签名称 tagName if tagName 非空;否则返回任何先前同级元素。返回 null 元素若不存在这样的同级。

另请参阅 firstChildElement (), nextSiblingElement (),和 lastChildElement ().

QDomNode QDomNode:: removeChild (const QDomNode & oldChild )

移除 oldChild from the list of children. oldChild 必须是此节点的直接子级。

返回新的引用为 oldChild 当成功时或 null 节点 当故障时。

另请参阅 insertBefore (), insertAfter (), replaceChild (),和 appendChild ().

QDomNode QDomNode:: replaceChild (const QDomNode & newChild , const QDomNode & oldChild )

替换 oldChild with newChild . oldChild 必须是此节点的直接子级。

newChild 是另一节点的子级,它会重设父级到此节点。若 newChild 是此节点的子级,那么它在子级列表中的位置会改变。

newChild QDomDocumentFragment ,那么 oldChild 被片段的所有子级所替换。

返回新的引用为 oldChild 当成功时或 null 节点 an failure.

另请参阅 insertBefore (), insertAfter (), removeChild (),和 appendChild ().

void QDomNode:: save ( QTextStream & stream , int indent , EncodingPolicy encodingPolicy = QDomNode::EncodingFromDocument) const

将节点及其所有子级的 XML 表示写入流 stream 。此函数使用 indent 作为节点的缩进空格数。

若文档包含无效 XML 字符或不能以给定编码编码字符,结果和行为未定义。

encodingPolicy is QDomNode::EncodingFromDocument 和此节点是文档节点,编码的文本流 stream 的编码是通过将名称 xml 的处理指令视为 XML 声明来设置的 (若存在一个的话),否则默认为 UTF-8。XML 声明不是处理指令,但由于历史原因而存在此行为。若此节点不是文档节点,使用文本流编码。

encodingPolicy is EncodingFromTextStream 和此节点是文档节点,此函数行为如 save( QTextStream &str, int indent) 除了指定编码在文本流 stream 的使用。

若文档包含无效 XML 字符或不能以给定编码编码字符,结果和行为未定义。

该函数在 Qt 4.2 引入。

void QDomNode:: setNodeValue (const QString & v )

将节点值设为 v .

另请参阅 nodeValue ().

void QDomNode:: setPrefix (const QString & pre )

若节点拥有名称空间前缀,此函数将节点名称空间前缀改为 pre 。否则此函数什么都不做。

仅节点为类型 ElementNode or AttributeNode 可以拥有名称空间。必须在创建时指定名称空间前缀;之后添加名称空间前缀是不可能的。

另请参阅 prefix (), localName (), namespaceURI (), QDomDocument::createElementNS (),和 QDomDocument::createAttributeNS ().

QDomAttr QDomNode:: toAttr () const

转换 QDomNode QDomAttr 。若节点不是属性,返回对象将是 null .

另请参阅 isAttr ().

QDomCDATASection QDomNode:: toCDATASection () const

转换 QDomNode QDomCDATASection 。若节点不是 CDATA 区间,返回对象将是 null .

另请参阅 isCDATASection ().

QDomCharacterData QDomNode:: toCharacterData () const

转换 QDomNode QDomCharacterData 。若节点不是字符数据,返回对象将是 null .

另请参阅 isCharacterData ().

QDomComment QDomNode:: toComment () const

转换 QDomNode QDomComment 。若节点不是注释,返回对象将是 null .

另请参阅 isComment ().

QDomDocument QDomNode:: toDocument () const

转换 QDomNode QDomDocument 。若节点不是文档,返回对象将是 null .

另请参阅 isDocument ().

QDomDocumentFragment QDomNode:: toDocumentFragment () const

转换 QDomNode QDomDocumentFragment 。若节点不是文档片段,返回对象将是 null .

另请参阅 isDocumentFragment ().

QDomDocumentType QDomNode:: toDocumentType () const

转换 QDomNode QDomDocumentType 。若节点不是文档类型,返回对象将是 null .

另请参阅 isDocumentType ().

QDomElement QDomNode:: toElement () const

转换 QDomNode QDomElement 。若节点不是元素,返回对象将是 null .

另请参阅 isElement ().

QDomEntity QDomNode:: toEntity () const

转换 QDomNode QDomEntity 。若节点不是实体,返回对象将是 null .

另请参阅 isEntity ().

QDomEntityReference QDomNode:: toEntityReference () const

转换 QDomNode QDomEntityReference 。若节点不是实体引用,返回对象将是 null .

另请参阅 isEntityReference ().

QDomNotation QDomNode:: toNotation () const

转换 QDomNode QDomNotation 。若节点不是表示法,返回对象将是 null .

另请参阅 isNotation ().

QDomProcessingInstruction QDomNode:: toProcessingInstruction () const

转换 QDomNode QDomProcessingInstruction 。若节点不是处理指令,返回对象将是 null .

另请参阅 isProcessingInstruction ().

QDomText QDomNode:: toText () const

转换 QDomNode QDomText 。若节点不是文本,返回对象将是 null .

另请参阅 isText ().

bool QDomNode:: operator!= (const QDomNode & n ) const

返回 true if n 和此 DOM 节点不相等;否则返回 false .

QDomNode &QDomNode:: operator= (const QDomNode & n )

赋值副本为 n 到此 DOM (文档对象模型) 节点。

拷贝数据是共享的 (浅拷贝):修改一个节点也将改变另一节点。若想要制作深度副本,使用 cloneNode ().

bool QDomNode:: operator== (const QDomNode & n ) const

返回 true if n 和此 DOM 节点相等;否则返回 false .

Any instance of QDomNode acts as a reference to an underlying data structure in QDomDocument . The test for equality checks if the two references point to the same underlying node. For example:

QDomDocument document;
QDomElement element1 = document.documentElement();
QDomElement element2 = element1;
					

2 节点 ( QDomElement QDomNode subclass) both refer to the document's root element, and element1 == element2 will return true. On the other hand:

QDomElement element3 = document.createElement("MyElement");
QDomElement element4 = document.createElement("MyElement");
					

Even though both nodes are empty elements carrying the same name, element3 == element4 will return false because they refer to two different nodes in the underlying data structure.

相关非成员

QTextStream & operator<< ( QTextStream & str , const QDomNode & node )

写入 XML 表示在节点 node 及其所有子级到流 str .