Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.*;

public class Main {
    /**
     * replace the text value in the target
     *
     * @param target
     * @param value
     * @return
     */
    public static boolean replaceTextValue(final Element target, final String value) {
        if (target == null) {
            return false;
        }
        final NodeList nodeList = target.getChildNodes();
        if (nodeList == null) {
            return false;
        }
        for (int current = 0; current < nodeList.getLength(); current++) {
            final Node node = nodeList.item(current);
            if (node instanceof Text) {
                final Text text = (Text) node;
                text.setData(value);
                return true;
            }
        }
        return false;
    }
}