Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

Change node value

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
liamgannon
Asked:
liamgannon
1 Solution
 
objectsCommented:
get the text child node and call setNodeValue()
0
 
maheshexpCommented:
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
 
objectsCommented:
> if( child.getNodeName().equals ("display-name")) ){

no that will throw a NPE
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mayank SAssociate Director - Product EngineeringCommented:
Indeed, it would.
0
 
liamgannonAuthor Commented:
Cheers objects ;-)
0
 
objectsCommented:
No worries :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now