protected static SOAPElement replaceElementWithSOAPElement(Element element, ElementImpl copy) { Iterator eachAttribute = getAllAttributesFrom(element); while (eachAttribute.hasNext()) { Name name = (Name) eachAttribute.next(); copy.addAttributeBare(name, getAttributeValueFrom(element, name)); } Iterator eachChild = getChildElementsFrom(element); while (eachChild.hasNext()) { Node nextChild = (Node) eachChild.next(); copy.insertBefore(nextChild, null); } Node parent = element.getParentNode(); if (parent != null) { parent.replaceChild(copy, element); } // XXX else throw an exception? return copy; }