009.xml (1961B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>DOM Traversal: NodeIterator: Removal of an ancestor of the Reference Node (backwards) (deep check)</title> 4 <script type="text/javascript"> <![CDATA[ 5 var errors = 0; 6 var log = ''; 7 function doTest() { 8 var iterator = document.createNodeIterator(document.getElementById('root'), NodeFilter.SHOW_ALL, null, false); 9 var root = document.getElementById('root'); 10 var A = document.getElementById('A'); 11 var B = document.getElementById('B'); 12 var BB = document.getElementById('BB'); 13 var C = document.getElementById('C'); 14 check(iterator.nextNode(), root); 15 check(iterator.nextNode(), A); 16 check(iterator.nextNode(), B); 17 check(iterator.nextNode(), BB); 18 check(iterator.previousNode(), BB); 19 remove(B); 20 var X = addChildTo(A); 21 check(iterator.previousNode(), X); 22 if (errors) 23 document.getElementById('result').firstChild.data = 'FAIL: ' + errors + ' errors:\n' + log; 24 else 25 document.getElementById('result').firstChild.data = 'PASS'; 26 } 27 function check(a, b) { 28 if (!a) { 29 errors += 1; 30 log += 'Found null but expected ' + b + ' (' + b.id + ').\n'; 31 } else if (a != b) { 32 errors += 1; 33 log += 'Found ' + a + ' (' + a.id + ') but expected ' + b + ' (' + b.id + ').\n'; 34 } 35 } 36 function remove(a) { 37 if (!a) { 38 errors += 1; 39 log += 'Tried removing null node.\n'; 40 } else 41 a.parentNode.removeChild(a); 42 } 43 function addChildTo(a) { 44 var x = document.createElementNS('http://www.w3.org/1999/xhtml', 'span'); 45 x.id = 'X'; 46 a.appendChild(x); 47 return x; 48 } 49 ]]></script> 50 </head> 51 <body onload="doTest()"> 52 <pre id="result">FAIL: Script did not complete.</pre> 53 <p><span id="root"><span id="A"></span><span id="B"><span id="BB"></span></span><span id="C"></span></span></p> 54 </body> 55 </html>