继承者: QDomAttr , QDomCDATASection , QDomCharacterData , QDomComment , QDomDocument , QDomDocumentFragment , QDomDocumentType , QDomElement , QDomEntity , QDomEntityReference , QDomNotation , QDomProcessingInstruction , QDomText
def
__eq__
(arg__1)
def
__ne__
(arg__1)
def
appendChild
(newChild)
def
attributes
()
def
childNodes
()
def
clear
()
def
cloneNode
([deep=true])
def
columnNumber
()
def
firstChild
()
def
firstChildElement
([tagName=””])
def
hasAttributes
()
def
hasChildNodes
()
def
insertAfter
(newChild, refChild)
def
insertBefore
(newChild, refChild)
def
isAttr
()
def
isCDATASection
()
def
isCharacterData
()
def
isComment
()
def
isDocument
()
def
isDocumentFragment
()
def
isDocumentType
()
def
isElement
()
def
isEntity
()
def
isEntityReference
()
def
isNotation
()
def
isNull
()
def
isProcessingInstruction
()
def
isSupported
(feature, version)
def
isText
()
def
lastChild
()
def
lastChildElement
([tagName=””])
def
lineNumber
()
def
localName
()
def
namedItem
(name)
def
namespaceURI
()
def
nextSibling
()
def
nextSiblingElement
([taName=””])
def
nodeName
()
def
nodeType
()
def
nodeValue
()
def
normalize
()
def
ownerDocument
()
def
parentNode
()
def
prefix
()
def
previousSibling
()
def
previousSiblingElement
([tagName=””])
def
removeChild
(oldChild)
def
replaceChild
(newChild, oldChild)
def
save
(arg__1, arg__2[, arg__3=QDomNode.EncodingFromDocument])
def
setNodeValue
(arg__1)
def
setPrefix
(pre)
def
toAttr
()
def
toCDATASection
()
def
toCharacterData
()
def
toComment
()
def
toDocument
()
def
toDocumentFragment
()
def
toDocumentType
()
def
toElement
()
def
toEntity
()
def
toEntityReference
()
def
toNotation
()
def
toProcessingInstruction
()
def
toText
()
Many functions in the DOM return a
QDomNode.可以找出节点的类型使用
isAttr(),isCDATASection(),isDocumentFragment(),isDocument(),isDocumentType(),isElement(),isEntityReference(),isText(),isEntity(),isNotation(),isProcessingInstruction(),isCharacterData()andisComment().A
QDomNodecan be converted into one of its subclasses usingtoAttr(),toCDATASection(),toDocumentFragment(),toDocument(),toDocumentType(),toElement(),toEntityReference(),toText(),toEntity(),toNotation(),toProcessingInstruction(),toCharacterData()ortoComment(). You can convert a node to a null node withclear().Copies of the
QDomNodeclass 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 aQDomNode,如firstChild(). You can make an independent (deep) copy of the node withcloneNode().A
QDomNodecan be null, much likeNone. 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 aQDomNodeis null by callingisNull(). The empty constructor of aQDomNode(or any of the derived classes) creates a null node.插入节点采用
insertBefore(),insertAfter()orappendChild(). You can replace one node with another usingreplaceChild()and remove a node withremoveChild().要遍历节点使用
firstChild()to get a node’s first child (if any), andnextSibling()to traverse.QDomNodealso provideslastChild(),previousSibling()andparentNode(). To find the first child node with a particular node name usenamedItem().要找出节点是否拥有子级使用
hasChildNodes()and to get a list of all of a node’s children usechildNodes().The node’s name and value (the meaning of which varies depending on its type) is returned by
nodeName()andnodeValue()respectively. The node’s type is returned bynodeType(). The node’s value can be set withsetNodeValue().节点所属文档的返回通过
ownerDocument().相邻
QDomText节点可以合并成单个节点采用normalize().
QDomElement可以检索节点拥有的属性采用attributes().
QDomElementandQDomAttr节点可以拥有可以检索的名称空间采用namespaceURI(). Their local name is retrieved withlocalName(), and their prefix withprefix(). The prefix can be set withsetPrefix().可以将节点的 XML 表示写入文本流采用
save().以下范例查找 XML 文档第一元素并打印其直接子级所有元素的名称。
d = QDomDocument() d.setContent(someXML) n = d.firstChild() while !n.isNull(): if n.isElement(): e = n.toElement() print "Element name: %s" % e.tagName() break n = n.nextSibling()有关文档对象模型的进一步信息,见 级别 1 and 级别 2 核心 。有关 DOM 实现的更一般介绍,见
QDomDocument文档编制。
QDomNode
¶
QDomNode(arg__1)
- param arg__1
构造
null
节点。
构造副本为
n
.
拷贝数据是共享的 (浅拷贝):修改一个节点也将改变另一节点。若想要制作深度副本,使用
cloneNode()
.
PySide2.QtXml.QDomNode.
NodeType
¶
此枚举定义节点的类型:
|
常量 |
描述 |
|---|---|
|
QDomNode.ElementNode |
|
|
QDomNode.AttributeNode |
|
|
QDomNode.TextNode |
|
|
QDomNode.CDATASectionNode |
|
|
QDomNode.EntityReferenceNode |
|
|
QDomNode.EntityNode |
|
|
QDomNode.ProcessingInstructionNode |
|
|
QDomNode.CommentNode |
|
|
QDomNode.DocumentNode |
|
|
QDomNode.DocumentTypeNode |
|
|
QDomNode.DocumentFragmentNode |
|
|
QDomNode.NotationNode |
|
|
QDomNode.BaseNode |
|
|
QDomNode.CharacterDataNode |
PySide2.QtXml.QDomNode.
EncodingPolicy
¶
此枚举指定如何
save()
determines what encoding to use when serializing.
|
常量 |
描述 |
|---|---|
|
QDomNode.EncodingFromDocument |
编码抓取自文档。 |
|
QDomNode.EncodingFromTextStream |
编码抓取自
|
另请参阅
PySide2.QtXml.QDomNode.
appendChild
(
newChild
)
¶
追加
newChild
as the node’s last child.
若
newChild
是另一节点的子级,它会重设父级到此节点。若
newChild
是此节点的子级,那么它在子级列表中的位置会改变。
若
newChild
是
QDomDocumentFragment
,那么片段的子级将从片段中移除并追加。
若
newChild
是
QDomElement
和此节点是
QDomDocument
,已经拥有的元素节点将作为子级,
newChild
不添加作为子级并返回 null 节点。
返回新的引用为
newChild
当成功时或
null
node
当失败时。
在 null 节点 (例如:采用默认构造函数创建) 调用此函数什么都不做并返回
null
node
.
DOM 规范禁止插入属性节点,但由于历史原因,无论如何 QDom 接受它们。
PySide2.QtXml.QDomNode.
attributes
(
)
¶
返回所有属性的命名节点映射。才提供属性对于
QDomElement
s.
改变映射中的属性也会改变其属性对于此
QDomNode
.
PySide2.QtXml.QDomNode.
childNodes
(
)
¶
返回所有直接子级节点的列表。
大多数情况下,会调用此函数在
QDomElement
对象。
例如,若 XML 文档看起来像这样:
<body>
<h1>Heading</h1>
<p>Hello <b>you</b></p>
</body>
Then the list of child nodes for the “body”-element will contain the node created by the <h1> tag and the node created by the <p> tag.
列表中的节点不是副本;因此改变列表中的节点也会改变此节点的子级。
另请参阅
PySide2.QtXml.QDomNode.
cloneNode
(
[
deep=true
]
)
¶
deep
–
bool
创建深 (非浅) 副本为
QDomNode
.
若
deep
is true, then the cloning is done recursively which means that all the node’s children are deep copied too. If
deep
为 false 仅节点本身被拷贝且副本没有子级节点。
PySide2.QtXml.QDomNode.
columnNumber
(
)
¶
int
对于创建的节点通过
setContent()
, this function returns the column number in the XML document where the node was parsed. Otherwise, -1 is returned.
另请参阅
PySide2.QtXml.QDomNode.
firstChild
(
)
¶
返回节点的第一子级。若没有子级节点,
null
node
被返回。改变返回节点也会改变文档树节点。
另请参阅
PySide2.QtXml.QDomNode.
firstChildElement
(
[
tagName=""
]
)
¶
tagName – unicode
返回的第一子级元素具有标签名称
tagName
若 tagName 非空; 否则返回第一子级元素。返回 null 元素若不存在这样的子级。
PySide2.QtXml.QDomNode.
hasAttributes
(
)
¶
bool
返回
true
若节点拥有属性;否则返回
false
.
另请参阅
PySide2.QtXml.QDomNode.
hasChildNodes
(
)
¶
bool
返回
true
若节点拥有一个或多个子级;否则返回
false
.
PySide2.QtXml.QDomNode.
insertAfter
(
newChild
,
refChild
)
¶
插入节点
newChild
后于子级节点
refChild
.
refChild
必须是此节点的直接子级。若
refChild
is
null
then
newChild
is appended as this node’s last child.
若
newChild
是另一节点的子级,它会重设父级到此节点。若
newChild
是此节点的子级,那么它在子级列表中的位置会改变。
若
newChild
是
QDomDocumentFragment
,那么片段的子级将从片段被移除并插入后于
refChild
.
返回新的引用为
newChild
当成功时或
null
node
当失败时。
DOM 规范禁止插入属性节点,但由于历史原因 QDom 仍然接受它们。
PySide2.QtXml.QDomNode.
insertBefore
(
newChild
,
refChild
)
¶
插入节点
newChild
前于子级节点
refChild
.
refChild
必须是此节点的直接子级。若
refChild
is
null
then
newChild
is inserted as the node’s first child.
若
newChild
是另一节点的子级,它会重设父级到此节点。若
newChild
是此节点的子级,那么它在子级列表中的位置会改变。
若
newChild
是
QDomDocumentFragment
,那么片段的子级将从片段被移除并插入前于
refChild
.
返回新的引用为
newChild
当成功时或
null
node
当失败时。
DOM 规范禁止插入属性节点,但由于历史原因 QDom 仍然接受它们。
PySide2.QtXml.QDomNode.
isAttr
(
)
¶
bool
返回
true
若节点是属性;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是 QDomAttribute;可以采用 toAttribute() 获取 QDomAttribute。
另请参阅
PySide2.QtXml.QDomNode.
isCDATASection
(
)
¶
bool
返回
true
若节点是 CDATA 区间;否则返回 false。
若此函数返回
true
,它并未暗示此对象是
QDomCDATASection
;可以获取
QDomCDATASection
with
toCDATASection()
.
另请参阅
PySide2.QtXml.QDomNode.
isCharacterData
(
)
¶
bool
返回
true
若节点是字符数据节点;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是
QDomCharacterData
;可以获取
QDomCharacterData
with
toCharacterData()
.
另请参阅
PySide2.QtXml.QDomNode.
isComment
(
)
¶
bool
返回
true
若节点是注释;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是
QDomComment
;可以获取
QDomComment
with
toComment()
.
另请参阅
PySide2.QtXml.QDomNode.
isDocument
(
)
¶
bool
返回
true
若节点是文档;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是
QDomDocument
;可以获取
QDomDocument
with
toDocument()
.
另请参阅
PySide2.QtXml.QDomNode.
isDocumentFragment
(
)
¶
bool
返回
true
若节点是文档片段;否则返回 false。
若此函数返回
true
,它并未暗示此对象是
QDomDocumentFragment
;可以获取
QDomDocumentFragment
with
toDocumentFragment()
.
另请参阅
PySide2.QtXml.QDomNode.
isDocumentType
(
)
¶
bool
返回
true
若节点是文档类型;否则返回 false。
若此函数返回
true
,它并未暗示此对象是
QDomDocumentType
;可以获取
QDomDocumentType
with
toDocumentType()
.
另请参阅
PySide2.QtXml.QDomNode.
isElement
(
)
¶
bool
返回
true
若节点是元素;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是
QDomElement
;可以获取
QDomElement
with
toElement()
.
另请参阅
PySide2.QtXml.QDomNode.
isEntity
(
)
¶
bool
返回
true
若节点是实体;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是
QDomEntity
;可以获取
QDomEntity
with
toEntity()
.
另请参阅
PySide2.QtXml.QDomNode.
isEntityReference
(
)
¶
bool
返回
true
若节点是实体引用;否则返回 false。
若此函数返回
true
,它并未暗示此对象是
QDomEntityReference
;可以获取
QDomEntityReference
with
toEntityReference()
.
另请参阅
PySide2.QtXml.QDomNode.
isNotation
(
)
¶
bool
返回
true
若节点是表示法;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是
QDomNotation
;可以获取
QDomNotation
with
toNotation()
.
另请参阅
PySide2.QtXml.QDomNode.
isNull
(
)
¶
bool
返回
true
若此节点为 null (即:若它没有类型或内容);否则返回
false
.
PySide2.QtXml.QDomNode.
isProcessingInstruction
(
)
¶
bool
返回
true
若节点是处理指令;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是
QDomProcessingInstruction
;可以获取 QProcessingInstruction 采用
toProcessingInstruction()
.
PySide2.QtXml.QDomNode.
isSupported
(
feature
,
version
)
¶
feature – unicode
version – unicode
bool
返回
true
若 DOM (文档对象模型) 实现实现特征
feature
且此特征由此节点支持在版本
version
;否则返回
false
.
另请参阅
PySide2.QtXml.QDomNode.
isText
(
)
¶
bool
返回
true
若节点是文本节点;否则返回
false
.
若此函数返回
true
,它并未暗示此对象是
QDomText
;可以获取
QDomText
with
toText()
.
另请参阅
PySide2.QtXml.QDomNode.
lastChildElement
(
[
tagName=""
]
)
¶
tagName – unicode
返回的最后子级元素具有标签名称
tagName
若 tagName 非空;否则返回最后子级元素。返回 null 元素,若不存在这种子级。
PySide2.QtXml.QDomNode.
lineNumber
(
)
¶
int
对于创建的节点通过
setContent()
, this function returns the line number in the XML document where the node was parsed. Otherwise, -1 is returned.
PySide2.QtXml.QDomNode.
localName
(
)
¶
unicode
若节点使用名称空间,此函数返回节点的本地名称;否则它返回空字符串。
仅节点为类型
ElementNode
or
AttributeNode
可以拥有名称空间。名称空间必须在创建时指定;之后添加名称空间不可能。
PySide2.QtXml.QDomNode.
namedItem
(
name
)
¶
name – unicode
返回第一直接子级节点对于其
nodeName()
等于
name
.
若不存在这种直接子级,
null
node
被返回。
另请参阅
PySide2.QtXml.QDomNode.
namespaceURI
(
)
¶
unicode
返回此节点的名称空间 URI 或空字符串,若节点没有名称空间 URI。
仅节点为类型
ElementNode
or
AttributeNode
可以拥有名称空间。名称空间 URI 必须在创建时指定且以后不能更改。
PySide2.QtXml.QDomNode.
nextSibling
(
)
¶
返回文档树中的下一同级。改变返回节点还会改变文档树中的节点。
若拥有的 XML 像这样:
<h1>Heading</h1>
<p>The text...</p>
<h2>Next heading</h2>
和此
QDomNode
represents the <p> tag, will return the node representing the <h2> tag.
另请参阅
PySide2.QtXml.QDomNode.
nextSiblingElement
(
[
taName=""
]
)
¶
taName – unicode
返回的下一同级元素具有标签名称
tagName
if
tagName
非空;否则返回任何下一同级元素。返回 null 元素,若不存在这种同级。
PySide2.QtXml.QDomNode.
nodeName
(
)
¶
unicode
返回节点的名称。
名称的含义从属子类:
|
Name |
含义 |
|
属性名称 |
|
|
The string “#cdata-section” |
|
|
The string “#comment” |
|
|
The string “#document” |
|
|
The string “#document-fragment” |
|
|
文件类型的名称 |
|
|
标签名称 |
|
|
实体名称 |
|
|
引用实体的名称 |
|
|
表示法名称 |
|
|
处理指令的目标 |
|
|
The string “#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()
.
另请参阅
PySide2.QtXml.QDomNode.
nodeValue
(
)
¶
unicode
返回节点的值。
值的含义从属子类:
|
Name |
含义 |
|
属性值 |
|
|
CDATA 区间的内容 |
|
|
注释 |
|
|
处理指令的数据 |
|
|
文本 |
All the other subclasses do not have a node value and will return an empty string.
另请参阅
PySide2.QtXml.QDomNode.
normalize
(
)
¶
Calling 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).
PySide2.QtXml.QDomNode.
__ne__
(
arg__1
)
¶
arg__1
–
QDomNode
bool
返回
true
if
n
和此 DOM 节点不相等;否则返回
false
.
PySide2.QtXml.QDomNode.
__eq__
(
arg__1
)
¶
arg__1
–
QDomNode
bool
返回
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.
PySide2.QtXml.QDomNode.
ownerDocument
(
)
¶
返回此节点所属的文档。
PySide2.QtXml.QDomNode.
prefix
(
)
¶
unicode
返回节点名称空间前缀,或空字符串若节点没有名称空间前缀。
仅节点为类型
ElementNode
or
AttributeNode
可以拥有名称空间。必须在创建时指定名称空间前缀。若节点是采用名称空间前缀创建的,可以稍后改变它采用
setPrefix()
.
如果创建元素或属性采用
createElement()
or
createAttribute()
, the prefix will be an empty string. If you use
createElementNS()
or
createAttributeNS()
instead, the prefix will not be an empty string; but it might be an empty string if the name does not have a prefix.
PySide2.QtXml.QDomNode.
previousSibling
(
)
¶
返回文档树的上一同级。改变返回节点也会改变文档树节点。
例如,若拥有的 XML 像这样:
<h1>Heading</h1>
<p>The text...</p>
<h2>Next heading</h2>
和此
QDomNode
represents the <p> tag, will return the node representing the <h1> tag.
另请参阅
PySide2.QtXml.QDomNode.
previousSiblingElement
(
[
tagName=""
]
)
¶
tagName – unicode
返回的上一同级元素具有标签名称
tagName
if
tagName
非空;否则返回任何先前同级元素。返回 null 元素若不存在这样的同级。
PySide2.QtXml.QDomNode.
removeChild
(
oldChild
)
¶
移除
oldChild
from the list of children.
oldChild
必须是此节点的直接子级。
返回新的引用为
oldChild
当成功时或
null
node
当失败时。
PySide2.QtXml.QDomNode.
replaceChild
(
newChild
,
oldChild
)
¶
替换
oldChild
with
newChild
.
oldChild
必须是此节点的直接子级。
若
newChild
是另一节点的子级,它会重设父级到此节点。若
newChild
是此节点的子级,那么它在子级列表中的位置会改变。
若
newChild
是
QDomDocumentFragment
,那么
oldChild
被片段的所有子级所替换。
返回新的引用为
oldChild
当成功时或
null
node
当失败时。
PySide2.QtXml.QDomNode.
save
(
arg__1
,
arg__2
[
,
arg__3=QDomNode.EncodingFromDocument
]
)
¶
arg__1
–
QTextStream
arg__2
–
int
arg__3
–
EncodingPolicy
将节点及其所有子级的 XML 表示写入流
stream
。此函数使用
indent
作为节点的缩进空格数。
若文档包含无效 XML 字符或不能以给定编码编码字符,结果和行为未定义。
若
encodingPolicy
is
EncodingFromDocument
和此节点是文档节点,编码的文本流
stream
‘s encoding is set by treating a processing instruction by name “xml” as an XML declaration, if one exists, and otherwise defaults to UTF-8. XML declarations are not processing instructions, but this behavior exists for historical reasons. If this node is not a document node, the text stream’s encoding is used.
若
encodingPolicy
is
EncodingFromTextStream
和此节点是文档节点,此函数行为如 save(
QTextStream
&str, int indent) 除了指定编码在文本流
stream
被使用。
若文档包含无效 XML 字符或不能以给定编码编码字符,结果和行为未定义。
PySide2.QtXml.QDomNode.
setNodeValue
(
arg__1
)
¶
arg__1 – unicode
Sets the node’s value to
v
.
另请参阅
PySide2.QtXml.QDomNode.
setPrefix
(
pre
)
¶
pre – unicode
若节点拥有名称空间前缀,此函数将节点名称空间前缀改为
pre
。否则此函数什么都不做。
仅节点为类型
ElementNode
or
AttributeNode
可以拥有名称空间。必须在创建时指定名称空间前缀;之后添加名称空间前缀是不可能的。
PySide2.QtXml.QDomNode.
toCDATASection
(
)
¶
转换
QDomNode
成
QDomCDATASection
。若节点不是 CDATA 区间,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toCharacterData
(
)
¶
转换
QDomNode
成
QDomCharacterData
。若节点不是字符数据,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toComment
(
)
¶
转换
QDomNode
成
QDomComment
。若节点不是注释,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toDocument
(
)
¶
转换
QDomNode
成
QDomDocument
。若节点不是文档,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toDocumentFragment
(
)
¶
转换
QDomNode
成
QDomDocumentFragment
。若节点不是文档片段,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toDocumentType
(
)
¶
转换
QDomNode
成
QDomDocumentType
。若节点不是文档类型,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toElement
(
)
¶
转换
QDomNode
成
QDomElement
。若节点不是元素,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toEntity
(
)
¶
转换
QDomNode
成
QDomEntity
。若节点不是实体,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toEntityReference
(
)
¶
转换
QDomNode
成
QDomEntityReference
。若节点不是实体引用,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toNotation
(
)
¶
转换
QDomNode
成
QDomNotation
。若节点不是表示法,返回对象将是
null
.
另请参阅
PySide2.QtXml.QDomNode.
toProcessingInstruction
(
)
¶
转换
QDomNode
成
QDomProcessingInstruction
。若节点不是处理指令,返回对象将是
null
.