It works fine, thanks , 
But if the Element is the root of the Document What is the parent? 

_______________________

Laurent Foret 
Service developpement
Developments department

> -----Message d'origine-----
> De : Arnaud Le Hors [mailto:[EMAIL PROTECTED]
> Envoye : vendredi 9 mars 2001 19:02
> A : [EMAIL PROTECTED]
> Objet : Re: setNodeName() ?
> 
> 
> 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]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to