1 56 57 62 63 package dom.html; 64 import org.enhydra.apache.html.dom.HTMLDOMImplementationImpl; 65 import org.w3c.dom.Attr ; 66 import org.w3c.dom.Element ; 67 import org.w3c.dom.Node ; 68 import org.w3c.dom.html.HTMLDOMImplementation; 69 import org.w3c.dom.html.HTMLDocument; 70 import org.w3c.dom.html.HTMLElement; 71 import org.w3c.dom.html.HTMLFormElement; 72 import org.w3c.dom.html.HTMLSelectElement; 73 74 import dom.util.Assertion; 75 76 79 public class Test { 80 83 private HTMLDocument createHTMLDocument() { 84 HTMLDOMImplementation domImpl = HTMLDOMImplementationImpl.getHTMLDOMImplementation(); 85 return domImpl.createHTMLDocument("test document"); 86 } 87 88 93 private void testNodeListShadowing() { 94 HTMLDocument document = createHTMLDocument(); 96 HTMLElement body = document.getBody(); 97 98 HTMLFormElement form = (HTMLFormElement)document.createElement("FORM"); 99 body.appendChild(form); 100 Attr attr3 = document.createAttribute("action"); 101 form.setAttributeNode(attr3); 102 103 Node node4 = document.createTextNode("http://www.nowhere.com"); 104 attr3.appendChild(node4); 105 106 node4 = document.createComment(" comment 1 "); 107 form.appendChild(node4); 108 109 node4 = document.createComment(" comment 2 "); 110 form.appendChild(node4); 111 112 Element elem4 = document.createElement("INPUT"); 113 form.appendChild(elem4); 114 Attr attr4 = document.createAttribute("type"); 115 elem4.setAttributeNode(attr4); 116 117 Node node5 = document.createTextNode("SUBMIT"); 118 attr4.appendChild(node5); 119 attr4 = document.createAttribute("value"); 120 elem4.setAttributeNode(attr4); 121 122 node5 = document.createTextNode("Fred"); 123 attr4.appendChild(node5); 124 125 node4 = document.createComment(" comment 3 "); 126 form.appendChild(node4); 127 128 HTMLSelectElement select = (HTMLSelectElement)document.createElement("SELECT"); 129 body.appendChild(select); 130 131 node4 = document.createComment(" comment 1 "); 132 select.appendChild(node4); 133 134 node4 = document.createComment(" comment 2 "); 135 select.appendChild(node4); 136 137 elem4 = document.createElement("OPTION"); 138 select.appendChild(elem4); 139 140 node5 = document.createTextNode("opt1"); 141 elem4.appendChild(node5); 142 143 elem4 = document.createElement("OPTION"); 144 select.appendChild(elem4); 145 146 node5 = document.createTextNode("opt2 "); 147 elem4.appendChild(node5); 148 149 node5 = document.createComment(" comment 3 "); 150 elem4.appendChild(node5); 151 152 Assertion.assertTrue(form.getChildNodes().getLength() == 4, 153 "form.getChildNodes().getLength() != 4"); 154 Assertion.assertTrue(form.getLength() == 1, 155 "form.getLength() != 1"); 156 Assertion.assertTrue(select.getChildNodes().getLength() == 4, 157 "select.getChildNodes().getLength() != 4"); 158 Assertion.assertTrue(select.getLength() == 2, 159 "select.getLength() != 2"); 160 } 161 162 165 public static void main(String [] args) { 166 Test test = new Test(); 167 test.testNodeListShadowing(); 168 } 169 } 170 171 | Popular Tags |