Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Element.copy() and Element(Element) bug

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Element.copy() and Element(Element) bug
  • Date: Thu, 23 Jun 2005 18:32:20 -0700

xom-1.0 and xom-1.1-CVS both have a bug in Element.copy() and Element (Element) where attributes are copied but the new attributes have a null parent due to a missing attr.setParent(...).

Here is the fix: Add a parent arg to Element.copyAttributes(), adjusting usage of copyAttributes in Element.java accordingly

private ArrayList copyAttributes(Element parent) {

int size = attributes.size();
ArrayList copy = new ArrayList(size);
for (int i = 0; i < size; i++) {
Node attr = ((Attribute) attributes.get(i)).copy();
attr.setParent(parent); // WH bug fix
copy.add(attr);
// copy.add(((Attribute) attributes.get(i)).copy());
}
return copy;

}

History: I'm experimenting with a simple yet powerful and efficient morphing method for use as an XQuery/XPath
insert, update and delete facility. One of the simpler tests makes a copy of a document via document.copy() and then detaches all attributes via attribute.detach(). Turns out the attributes are not detached at all. Quite probably a bug on my side I thought, but no, turns out they're not detached because their parent pointer is null as a result of document.copy()!

Wolfgang.




Archive powered by MHonArc 2.6.24.

Top of Page