Deferred Parsing - getElementById() produces wrong results, if ID-Attributes are removed
The CoreDocumentImpl holds a Hashtable<String, Element> called "identifiers". Using Deferred Parsing, the HTMLDocBuilder pushes elements with an ID-Attribute into this Hashtable.
LazyHTMLDocument(CoreDocumentImpl).putIdentifier(String, Element) line: 1218 HTMLDocBuilder.addAttribute(String, String) line: 155 TidyHTMLParser.createElement(Node) line: 159 TidyHTMLParser.makeDomNode(Node) line: 183 TidyHTMLParser.buildNode(Node) line: 203 TidyHTMLParser.buildNode(Node) line: 208 TidyHTMLParser.buildNode(Node) line: 208 TidyHTMLParser.buildNode(Node) line: 208 TidyHTMLParser.buildNode(Node) line: 208 TidyHTMLParser.buildNode(Node) line: 208 TidyHTMLParser.parse(InputSource, LineNumberMap, XMLCDomFactory, MetaData, ErrorReporter, ParseTracer) line: 360 Parse.parse(MetaData) line: 243 StandardDocumentLoader(DocumentLoaderImpl).parseDocument(Class, URL) line: 569 StandardDocumentLoader(DocumentLoaderImpl).getCacheEntry(Class) line: 179 StandardDocumentLoader(DocumentLoaderImpl).getDocument(Class) line: 236 html.buildDocument() line: not available html.(DocumentLoader, boolean) line: not available html.(DocumentLoader) line: not available NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method] NativeConstructorAccessorImpl.newInstance(Object[]) line: 39 DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27 Constructor.newInstance(Object...) line: 513 XMLCDeferredParsingFactory.createObject(Class) line: 113 XMLCDeferredParsingFactory.doCreate(Class) line: 139 XMLCDeferredParsingFactory(XMLCStdFactory).create(Class) line: 139 XMLCDeferredParsingFactory.createFromFile(String, String) line: 182 XMLCDeferredParsingFactory.createFromFile(String) line: 163
If you remove the ID-Attribute from one of those "cached" elements, the Hashtable is not updated. Then a call to "document.getElementById(String)" will answer the wrong (old) element.
HTML-Snippet:
<div id="findme"></div>
Java-Code:
Element div = document.getElementById("findme");
div.removeAttribute("id");
Element span = document.createElement("span");
span.setAttribute("id", "findme");
div.appendChild(span);
// ERROR document.getElementById("findme") returns still the DIV
HTML-Output is correct:
<div><span id="findme"></span></div>
Reproducable with XMLC 2.2.17 and 2.3.3.