Using Xerces parser and XHTML DOM, Node.appendChild() improperly inserts instead of appending
I'm using the XHTML DOM with the xerces parser on an XHTML 1.0 Strict document. When I append a series of nodes at runtime under the same parent, the last node I append is being inserted in front of all the other nodes, instead of appended. All of the other nodes, however, are appended in the proper order. I've verified with the debugger that the nodes are being fed in the proper order via a ListIterator.
Here's the relevant code snippets:
Iterator items = fooList.listIterator(); XHTMLDivElement template = page.getElementFooTemplate(); // Code removing id attributes on foo template node removed for simplicity
while (it.hasNext()) {
foo = (Foo) items.next();
XHTMLDivElement newNode = template.cloneNode(true);
parent.appendChild(newNode);
setFooStuff(newNode, foo);
}