if (attributes != null) {
for (int j = 0; j < attributes.getLength(); j++) {
Attr attribute = (Attr)attributes.item(j);
//Strangely, it is possible to get a null attribute from this collection... check for it
if (attribute != null) {
replacementNode.setAttributeNode((Attr)attribute.cloneNode(true));
}
}
}
//Replace the existing node with a new
parametersNode.replaceChild(replacementNode, toBeReplaced);