Java & XML-DOM. Change the tag name of an Element object.

D

David Portabella

Using the Java package org.w3c.dom,
I have an Element object.
How can I change the tagName of a given Element?

There is the method Element.getTagName(),
but I did not find the method Element.setTagName() or equivalent.

One solution could be to create a new Element, with the new name, move
all the children and attributes from the old element to the new one,
and to replace the old element for the new one in the tree.

Is there a simpler and more natural solution?
some xml util package (that works with org.w3c.dom)?

DAvid
 
M

Mike Schilling

David said:
Using the Java package org.w3c.dom,
I have an Element object.
How can I change the tagName of a given Element?

There is the method Element.getTagName(),
but I did not find the method Element.setTagName() or equivalent.

One solution could be to create a new Element, with the new name, move
all the children and attributes from the old element to the new one,
and to replace the old element for the new one in the tree.

Is there a simpler and more natural solution?

No. What you described is the only way to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top