Here is what renameElement could look like. This is off the top of my
head so there might be syntax errors.
void renameElement(Element el, String newName) {
// create element with new name
Element nel = el.getOwnerDocument().createElement(newName);
// move children
while (el.getFirstChild() != null) {
nel.appendChild(el.getFirstChild());
}
// move attributes
if (el.hasAttributes()) {
NamedNodeMap attrs = el.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Node at = attrs.item(i);
nel.setAttribute(at.getNodeName(), at.getNodeValue());
}
}
// insert the new element in place of the old one
Node parent = el.getParentNode();
parent.insertBefore(nel, el);
parent.removeChild(el);
}
If you deal with namespaces you'll need an extended version that takes
into account Namespace URIs. But it's basically the same.
--
Arnaud Le Hors - IBM Cupertino, XML Strategy Group
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]