如何使用Jdom重命名xml文件的元素

时间:2021-09-01 10:53:13

Thans for previous replies,

以前回复的Thans,

I am trying to rename the xml element using Jdom concept, I have given elementNode.setName(newTagName) for changing the element of the node but this command is not working. if anyone know how to change the element of the xml file, pls guide me.

我试图使用Jdom概念重命名xml元素,我已经给出了elementNode.setName(newTagName)来更改节点的元素,但是这个命令不起作用。如果有人知道如何更改xml文件的元素,请指导我。

1 个解决方案

#1


0  

I assume the problem you have is the name does not change in the XML file you loaded using JDOM.

我假设您遇到的问题是您使用JDOM加载的XML文件中的名称没有更改。

When modifying the nodes created by JDOM you don't modify the original file. You only change the in-memory JDOM data (that was loaded from your XML file). After doing the renaming you should thus write the JDOM tree to an XML file (the same you loaded data from or an other) to actually change it.

修改JDOM创建的节点时,不要修改原始文件。您只需更改内存中的JDOM数据(从XML文件加载)。在进行重命名后,您应该将JDOM树写入XML文件(与您加载的数据相同)以实际更改它。

#1


0  

I assume the problem you have is the name does not change in the XML file you loaded using JDOM.

我假设您遇到的问题是您使用JDOM加载的XML文件中的名称没有更改。

When modifying the nodes created by JDOM you don't modify the original file. You only change the in-memory JDOM data (that was loaded from your XML file). After doing the renaming you should thus write the JDOM tree to an XML file (the same you loaded data from or an other) to actually change it.

修改JDOM创建的节点时,不要修改原始文件。您只需更改内存中的JDOM数据(从XML文件加载)。在进行重命名后,您应该将JDOM树写入XML文件(与您加载的数据相同)以实际更改它。