Solved

Change node value

Posted on 2004-04-26
6
228 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
for i loop in grovy 1 46
javap bin 2 29
object oriented programming comparison 5 56
How to convert String matching to regex in java 4 21
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
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.

867 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

16 Experts available now in Live!

Get 1:1 Help Now