开发者

Java: Changing an xml node name without using renameNode()

开发者 https://www.devze.com 2023-01-04 14:09 出处:网络
I\'ve been renaming xml nodes using the document.renameNode() method: Document document = loadXml(xml);

I've been renaming xml nodes using the document.renameNode() method:

 Document document = loadXml(xml);

 NodeList list = document.getElementsByTagName("Entry1");
 for (int i=0; i < list.getLength();)
 {
    document.renameNode(list.item(i), "", "Entry");
 }

However, the Java version I'm deploying to (1.5.0_09-b03) doesn't support the renameNode method. Any ideas how I could write the above in a way that's compatible with this v开发者_如何学JAVAersion of Java?

Thanks in advance.


Hmm... the Java 1.5 API doc says renameNode() is supported. Are you sure you don't have access to that method? Are you using org.w3c.dom classes?


As mentioned in my comment I was able to do a replaceAll on the string replacing "Entry1" with "Entry" and then loading that as xml.

Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消