PHP DOM textContent vs nodeValue? [英] PHP DOM textContent vs nodeValue?
问题描述
PHP DOMnode对象包含 textContent 和nodeValue 属性,它们似乎都是节点的innerHTML。
nodeValue:此节点的值,具体取决于其类型
textContent:此属性返回这个节点及其后代的文本内容。
这两个属性有什么区别?什么时候使用一个而不是另一个?
我终于想知道差异,所以我挖进入来源,找到答案;在大多数情况下,将不会有明显的区别,但是您应该注意到一些边缘案例。
- > nodeValue
和 - > textContent
对于以下类(节点类型)是相同的:
-
DOMAttr
-
DOMText
-
DOMElement
-
DOMComment
-
DOMCharacterData
-
DOMProcessingInstruction
-
DOMNameSpaceNode
(没有记录,但可以可以使用//命名空间:*
selector)找到/ li>
DOMNameSpaceNode
(not documented, but can be found with//namespace:*
selector)
- > nodeValue
属性产生以下内容的 NULL
类(节点类型):
- > textContent
属性不存在以下课程:
以下类不存在 - > nodeValue
属性:
另请参见: dom_node_node_value_read()
和 dom_node_text_content_read()
PHP DOMnode objects contain a textContent and nodeValue attributes which both seem to be the innerHTML of the node.
nodeValue: The value of this node, depending on its type
textContent: This attribute returns the text content of this node and its descendants.
What is the difference between these two properties? When is it proper to use one instead of the other?
I finally wanted to know the difference as well, so I dug into the source and found the answer; in most cases there will be no discernible difference, but there are a bunch of edge cases you should be aware of.
Both ->nodeValue
and ->textContent
are identical for the following classes (node types):
The ->nodeValue
property yields NULL
for the following classes (node types):
The ->textContent
property is non-existent for the following classes:
The ->nodeValue
property is non-existent for the following classes:
See also: dom_node_node_value_read()
and dom_node_text_content_read()
这篇关于PHP DOM textContent vs nodeValue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!