<html>
<link rel="stylesheet" href="josh.css">
<body bgcolor="#FFFFFF">

		<div id="Description">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">TreeWalker</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">7</span> IE <span class="emphasis">n/a</span> DOM <span class="emphasis">2</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>The <span class="literal">TreeWalker</span> object is a live, hierarchical list
of nodes that meet criteria defined by the
<span class="literal">document.createTreeWalker( )</span> method. The list
assumes the same parent-descendant hierarchy for its items as the
nodes to which its items point. The <span class="literal">createTreeWalker(
)</span> method describes the node where the list begins and which
nodes (or classes of nodes) are exempt from the list by way of
filtering.
</p>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			The <span class="literal">TreeWalker</span> object maintains a kind of pointer
inside the list (so that your scripts don't have
to). Methods of this object let scripts access the next or previous
node (or sibling, child, or parent node) in the list, while moving
the pointer in the direction indicated by the method you chose. If
scripts modify the document tree after the
<span class="literal">TreeWalker</span> is created, changes to the document
tree are automatically reflected in the sequence of nodes in the
<span class="literal">TreeWalker</span>.
</p>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			While fully usable in an HTML document, the
<span class="literal">TreeWalker</span> can be even more valuable in an XML
data document. For example, the W3C DOM does not provide a quick way
to access all elements that have a particular attribute name
(something that the XPATH standard can do easily on the server). But
you can define a <span class="literal">TreeWalker</span> to point only to nodes
that have the desired attribute, and quickly access those nodes
sequentially (i.e., without having to script more laborious looping
through all nodes in search of the desired elements). As an example,
the following filter function allows only those nodes that contain
the <span class="literal">author</span> attribute to be a member of a
<span class="literal">TreeWalker</span> object:
</p>
<span class="PROGRAMLISTING"><pre>function authorAttrFilter(node) {
    if (node.hasAttribute(&quot;author&quot;)) {
        return NodeFilter.FILTER_ACCEPT;		
    }
    return NodeFilter.FILTER_SKIP;
}</pre></span>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			A reference to this function becomes one of the parameters to a
<span class="literal">createTreeWalker( )</span> method that also limits the
list to element nodes:
</p>
<span class="PROGRAMLISTING"><pre>var authorsOnly = document.createTreeWalker(document, 
NodeFilter.SHOW_ELEMENT, authorAttrFilter, false);</pre></span>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			You can then invoke <span class="literal">TreeWalker</span> object methods to
obtain a reference to one of the nodes in the list. When you invoke
the method, the <span class="literal">TreeWalker</span> object applies the
filter to candidates relative to the current poistion of the internal
pointer in the direction indicated by the method. The next document
tree node to meet the method and filter criteria is returned. Once
you have that node reference, you can access any DOM node property or
method to work with the node, independent of the items in the
<span class="literal">TreeWalker</span> list.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="objectmodelreference"><span class="title">Object Model Reference</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td><span class="programlisting"><pre><span class="replaceable">TreeWalkerReference</span></pre>
						</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="objectspecificproperties"><span class="title">Object-Specific Properties</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td>
						<table border="1"><tbody><tr><td><span class="literal">currentNode</span></td><td><span class="literal">expandEntityReference</span></td><td><span class="literal">filter</span></td><td><span class="literal">root</span></td><td><span class="literal">whatToShow</span></td>
								</tr>
							</tbody></table>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="objectspecificmethods"><span class="title">Object-Specific Methods</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td>
						<table border="1"><tbody><tr><td><span class="literal">firstChild( )</span></td><td><span class="literal">lastChild( )</span></td><td><span class="literal">nextNode( )</span></td><td><span class="literal">nextSibling( )</span></td>
								</tr>
								<tr><td><span class="literal">parentNode( )</span></td><td><span class="literal">previousNode( )</span></td><td><span class="literal">previousSibling( )</span></td><td></td>
								</tr>
							</tbody></table>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="objectspecificeventhandlerproperties"><span class="title">Object-Specific Event Handler Properties</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			None. </p>
					</td>
				</tr>
			</table>
		</div><div id="currentNode">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">currentNode</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">7</span> IE <span class="emphasis">n/a</span> DOM <span class="emphasis">2</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">Read/Write&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Returns a reference to the node where the
<span class="literal">TreeWalker</span>'s pointer is
positioned. But more importantly, you can also assign a document tree
node reference to this property to manually set a new position for
the pointer. If the assigned node would normally be filtered out of
the list, the next method invocation is performed from the position
as if the assigned node were not filtered out of the list.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="example"><span class="title">Example</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td><span class="programlisting"><pre>myTreeWalker.currentNode = document.getElementById("main");</pre>
						</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="value"><span class="title">Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Reference to a document tree node.</p>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap colspan="2" class="default"><span class="title">Default</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			First node of the document.</p>
					</td>
				</tr>
			</table>
		</div><div id="expandEntityReference, filter, root, whatToShow">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">expandEntityReference, filter, root, whatToShow</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">7</span> IE <span class="emphasis">n/a</span> DOM <span class="emphasis">2</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">Read-only&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>These four properties reflect the parameter values passed to the
<span class="literal">document.createTreeWalker( )</span> method when the
object was created.
</p>
												</td>
</tr>
			</table>
		</div><div id="firstChild( ), lastChild( ), nextSibling( ), parentNode( ), previousSibling( )">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">firstChild( ), lastChild( ), nextSibling( ), parentNode( ), previousSibling( )</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">7</span> IE <span class="emphasis">n/a</span> DOM <span class="emphasis">2</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>These methods return references to nodes within the hierarchy of
items in the <span class="literal">TreeWalker</span> object. The
parent-descendant relationships between nodes are identical to those
of the nodes within the document tree. As you invoke any one of these
methods, the <span class="literal">TreeWalker</span>'s
internal pointer moves to a position adjacent to the
node's spot within the <span class="literal">TreeWalker</span>
list. If there is no node meeting the desired reference, the method
returns <span class="literal">null</span>. This means that you need to verify
the existence of the node before reading any property of the node:
</p>
<span class="PROGRAMLISTING"><pre>if (myTreeWalker.nextSibling( )) {
    var theTag = myTreeWalker.currentNode.tagName;
}</pre></span>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			If you reference a property of a null reference directly
(<span class="literal">myTreeWalker.nextSibling( ).tagName</span>, for
example), a reference error results.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="parameters"><span class="title">Parameters</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			None. </p>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="returnedvalue"><span class="title">Returned Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Reference to a document tree node. </p>
					</td>
				</tr>
			</table>
		</div><div id="nextNode(   ), previousNode(   )">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">nextNode(   ), previousNode(   )</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">7</span> IE <span class="emphasis">n/a</span> DOM <span class="emphasis">2</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Move the internal <span class="literal">NodeIterator</span> pointer one
position forward (<span class="literal">nextNode( )</span>) or backward
(<span class="literal">previousNode( )</span>), while returning a reference to
the node through which the pointer passed en route. These two methods
operate as if the hierarchy were flattened (in the manner of a
<span class="literal">NodeIterator</span> object).
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="parameters"><span class="title">Parameters</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			None. </p>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="returnedvalue"><span class="title">Returned Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Reference to a node in the document tree. </p>
					</td>
				</tr>
			</table>
		</div>

</body>
</html>