Change node value

Posted on 2004-04-26
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:


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=
Question by:liamgannon
LVL 92

Accepted Solution

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

Expert Comment

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 */
LVL 92

Expert Comment

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

no that will throw a NPE
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.

Author Comment

ID: 10928045
Cheers objects ;-)
LVL 92

Expert Comment

ID: 10934405
No worries :)

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