Solved

Change node value

Posted on 2004-04-26
6
227 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
Comment Utility
get the text child node and call setNodeValue()
0
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
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
Comment Utility
> if( child.getNodeName().equals ("display-name")) ){

no that will throw a NPE
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
Indeed, it would.
0
 

Author Comment

by:liamgannon
Comment Utility
Cheers objects ;-)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
No worries :)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now