Solved

Change node value

Posted on 2004-04-26
6
230 Views
Last Modified: 2012-05-04
I have a method transverseDomTree() that goes through all the nodes in a DOM tree until it finds a node called "display-name". When it finds this node I want to change the value of the node ie change it from:

<display-name>Hello</display-name>
to
<display-name>Welcome</display-name>

How do i go about this?

public static void transverseDomTree(Node start){
          Node child;
          if(start.getNodeName().equals ("display-name")){
                //change value
          }
          for(child = start.getFirstChild();child!=null;child=
               child.getNextSibling()){
               transverseDomTree(child);
          }
}
0
Comment
Question by:liamgannon
6 Comments
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 10923642
get the text child node and call setNodeValue()
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10924128
i think it should not be like this...
>>start.getNodeName().equals ("display-name"))
since what ever u traverse, the start will point to the argument what u have passed....

i think it should be like this...

if( child.getNodeName().equals ("display-name")) ){
       /* set the value of the child using the method u desginated, or directly to the field */
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10924567
> if( child.getNodeName().equals ("display-name")) ){

no that will throw a NPE
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 30

Expert Comment

by:Mayank S
ID: 10925408
Indeed, it would.
0
 

Author Comment

by:liamgannon
ID: 10928045
Cheers objects ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 10934405
No worries :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL  on Tomcat 8 68
servlet filter example 37 72
eclipse console opening separately 2 29
Is Applet the way to go for my drag and drop system? 8 25
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question