#241 DOM Attribute not cloned properly

open
nobody
5
2012-10-08
2010-11-24
Marty Phelan
No

When cloning a DOM element, the attribute(s) of the cloned element are left linked to the original element. The problem only occurs if you have first traversed the original DOM element and its attributes (forces lazy instantiation). The problem does not show itself in the jtidy.pprint method -- only in the traversal of the DOM after the clone process. When you run the attached example program, notice the attributes of the 2 h1 elements are the same objects.

I was able to fix the problem by adding the following code to the org.w3c.tidy.AttVal.clone() method:

    if (this.adapter != null)
    {
      av.adapter = new DOMAttrImpl(av);
    }

Discussion

  • Marty Phelan
    Marty Phelan
    2010-11-24

    Sample program to re-create problem.

     
    Attachments