01: package demo.builder;
02:
03: import org.w3c.dom.*;
04:
05: public class TextMapper {
06: /**
07: * replace the textnode child of elm with str
08: */
09: public static void map(Node elm, String str) {
10: NodeList nodes = elm.getChildNodes();
11: for (int i = 0; i < nodes.getLength(); i++) {
12: Node node = nodes.item(i);
13: if (node instanceof Text) {
14: Text text = elm.getOwnerDocument().createTextNode(str);
15: elm.replaceChild(text, node);
16: break;
17: }
18: }
19: }
20: }
|