1 <html xmlns="http://www.w3.org/1999/xhtml">
3 <title>DOM Traversal: NodeIterator: Filters</title>
4 <script type="text/javascript"> <![CDATA[
6 if (window.testRunner) testRunner.dumpAsText();
7 var iterator = document.createNodeIterator(document, NodeFilter.SHOW_ALL, testFilter, false);
8 // skips text nodes and body element
9 var expected = new Array(9, // document
13 1, 4, // script and CDATA block
20 var found = new Array();
24 while (node = iterator.nextNode())
25 found.push(node.nodeType);
30 var length = (found.length > expected.length) ? found.length : expected.length;
31 s += 'EXPECTED FOUND\n';
32 for (var i = 0; i < length; i += 1) {
33 s += ' ' + (expected[i] ? expected[i] : '-') +
34 ' ' + (found[i] ? found[i] : '-');
35 if (found[i] != expected[i]) {
41 var p = document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'pre')[0];
43 p.firstChild.data = 'FAIL: ' + errors + ' errors found:\n\n' + s;
45 p.firstChild.data = 'PASS';
48 function testFilter(n) {
49 if (n.nodeType == 3) {
50 return NodeFilter.FILTER_SKIP;
51 } else if (n.nodeName == 'body') {
52 return NodeFilter.FILTER_REJECT; // same as _SKIP
54 return 1; // FILTER_ACCEPT
59 <body onload="doTest()">
60 <pre id="result">FAIL: Script failed to run.</pre>
62 <!-- some more nodes to test this: -->