TreeWalker

翻译不完整。 请帮助我们翻译这篇文章!

TreeWalker 对象用于表示文档子树中的节点和它们的位置。

TreeWalker 可以使用 Document.createTreeWalker() 方法创建。

属性

这个接口不继承任何属性。

TreeWalker.root 只读
返回一个 Node ,表示新建 TreeWalker 时所声明的根节点。
TreeWalker.whatToShow 只读
返回一个 unsigned long 类型的常量位掩码,表示需要筛选的Node 类型。不匹配的节点会跳过,但其子节点,如果符合条件,则也会被包含。可能的值如下:
常量 数字值 描述
NodeFilter.SHOW_ALL -1 (that is the max value of unsigned long) Shows all nodes.
NodeFilter.SHOW_ATTRIBUTE 2 Shows attribute Attr nodes. This is meaningful only when creating a TreeWalker with an Attr node as its root. In this case, it means that the attribute node will appear in the first position of the iteration or traversal. Since attributes are never children of other nodes, they do not appear when traversing over the document tree.
NodeFilter.SHOW_CDATA_SECTION 8 Shows CDATASection nodes.
NodeFilter.SHOW_COMMENT 128 Shows Comment nodes.
NodeFilter.SHOW_DOCUMENT 256 Shows Document nodes.
NodeFilter.SHOW_DOCUMENT_FRAGMENT 1024 Shows DocumentFragment nodes.
NodeFilter.SHOW_DOCUMENT_TYPE 512 Shows DocumentType nodes.
NodeFilter.SHOW_ELEMENT 1 Shows Element nodes.
NodeFilter.SHOW_ENTITY 32 Shows Entity nodes. This is meaningful only when creating a TreeWalker with an Entity node as its root; in this case, it means that the Entity node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.
NodeFilter.SHOW_ENTITY_REFERENCE 16 Shows EntityReference nodes.
NodeFilter.SHOW_NOTATION 2048 Shows Notation nodes. This is meaningful only when creating a TreeWalker with a Notation node as its root; in this case, it means that the Notation node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.
NodeFilter.SHOW_PROCESSING_INSTRUCTION 64 Shows ProcessingInstruction nodes.
NodeFilter.SHOW_TEXT 4 Shows Text nodes.
TreeWalker.filter 只读
Returns a NodeFilter used to select the relevant nodes.
TreeWalker.expandEntityReferences 只读
Is a Boolean indicating, when discarding an EntityReference its whole sub-tree must be discarded at the same time.
TreeWalker.currentNode
Is the Node on which the TreeWalker is currently pointing at.

方法

这个接口不继承任何方法。

Note: in the context of a TreeWalker, a node is visible if it exists in the logical view determined by the whatToShow and filter parameter arguments. (Whether or not the node is visible on the screen is irrelevant.)

TreeWalker.parentNode()
Moves the current Node to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
TreeWalker.firstChild()
Moves the current Node to the first visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, returns null and the current node is not changed.
TreeWalker.lastChild()
Moves the current Node to the last visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, null is returned and the current node is not changed.
TreeWalker.previousSibling()
Moves the current Node to its previous sibling, if any, and returns the found sibling. If there is no such node, return null and the current node is not changed.
TreeWalker.nextSibling()
Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
TreeWalker.previousNode()
Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
TreeWalker.nextNode()
Moves the current Node to the next visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, returns null and the current node is not changed.

规范

规范 状态 注释
DOM
TreeWalker
Living Standard Removed the expandEntityReferences property.
Document Object Model (DOM) Level 2 Traversal and Range Specification
TreeWalker
Obsolete Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
TreeWalkerChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
currentNodeChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
expandEntityReferences
Deprecated
Chrome Full support 1Edge Full support 12Firefox No support 4 — 21IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android No support 4 — 21Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
filterChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
firstChildChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
lastChildChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
nextNodeChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
nextSiblingChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
parentNodeChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
previousNodeChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
previousSiblingChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
rootChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes
whatToShowChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support 3WebView Android Full support 3Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3Samsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.

参见