KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > builder > TextMapper


1 package demo.builder;
2
3 import org.w3c.dom.*;
4
5 public class TextMapper
6 {
7     /**
8      * replace the textnode child of elm with str
9      */

10     public static void map (Node elm, String JavaDoc str) {
11     NodeList nodes = elm.getChildNodes();
12     for (int i = 0 ; i < nodes.getLength(); i++) {
13         Node node = nodes.item(i);
14         if (node instanceof Text) {
15         Text text = elm.getOwnerDocument().createTextNode(str);
16         elm.replaceChild(text, node);
17         break;
18         }
19     }
20     }
21 }
22
23
Popular Tags