At 02:41 PM 9/24/2006, you wrote:
>Hi Jake,
>
>Jacob Kjome <[EMAIL PROTECTED]> wrote on 09/23/2006 02:44:20 AM:
>
><snip/>
>
>> What do you think of this (below). It actually goes one step further
>> by not necessarily counting on the parsing process to build up the
>> "identifiers" map. It first checks super.getElementById() (which
>> uses the "identifiers" map). If it finds the element, it returns it
>> immediately. No unnecessary recursion. If it doesn't find it, it
>> falls back to the pre-existing recursive behavior to find the
>> element. If it is found, it populates the "identifiers" map with the
>> element so the next call to getElementById() will be
>> optimized. Finally, it returns the element.
>>
>> public synchronized Element getElementById( String elementId )
>> {
>> Element idElement = super.getElementById(elementId);
>> if (idElement != null) {
>> return idElement;
>> }
>> idElement = getElementById( elementId, this );
>> if (idElement != null) {
>> putIdentifier(elementId, idElement);
>> }
>> return idElement;
>> }
>>
>> What do you think? With this in place, even if no parse-time
>> solution is found for HTML documents to populate the "identifiers"
>> map, there's still some optimization provided in the case that
>> getElementById() is called more than once on the same Id. I know,
>> it's kind of odd, but there are some situations where such a thing
>> happens and it doesn't hurt anything to account for it. And with a
>> parse-time solution, the less efficient recursion will never have to
>> be run because "identifiers" map will already have been populated
>> allowing for fully optimized access to elements with Ids.
>
>I don't think that's going to work. If after caching the id in the
>"identifiers" map the application changes the value of the id or removes
>it from the element the "identifers" map won't get updated so a subsequent
>call to getElementById() would return the wrong answer. Only modifications
>to ID attributes [1] get reflected in this map.
>
Ok, then how about...
public synchronized Element getElementById( String elementId )
{
Element idElement = super.getElementById(elementId);
if (idElement != null) {
return idElement;
}
idElement = getElementById( elementId, this );
if (idElement != null) {
idElement.setIdAttribute("id", true);
}
return idElement;
}
That seems to work just as well and seems like it addresses the issue
you just mentioned, no?
Jake
>
>[1]
>http://xerces.apache.org/xerces2-j/javadocs/api/org/w3c/dom/Attr.html#isId()
>
>Michael Glavassevich
>XML Parser Development
>IBM Toronto Lab
>E-mail: [EMAIL PROTECTED]
>E-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]