views:

34

answers:

2

Hi,

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 version of Java?

Thanks in advance.

A: 

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?

Jim Garrison
Hi Jim - I'm using the org.w3c.dom classes. The error I get on the server is: java.lang.NoSuchMethodError: org.w3c.dom.Document.renameNode
Zero Cool
Ah. Then the problem is that the server is not running Java 1.5, but probably a version of 1.4. You'll need to updgrade to 1.5. Otherwise I'm not sure this can be done prior to DOM3 and Java 1.5 without programming for yourself all the gyrations that renameNode() goes through. See the 1.5 Javadoc for renameNode() for a complete description of what it does. Maybe you can get away with a simpler version for your needs, but you'll essentially have to create a new node, copy the data, delete the old one and insert the new one.
Jim Garrison
Thanks Jim, unfortunately I won't be able to have the server version upgraded. The server does report running 1.5.0_09 so I find this odd for sure. Fortunately my solution was simple: do a replaceAll on the incoming xml string replacing "Entry1" with "Entry". Appreciate your help.
Zero Cool
A: 

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.

Zero Cool