Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.*;

public class Main {
    /**
     *  Sets the text for a node
     */
    public synchronized static void setText(Node n, String text) {
        if (n == null)
            throw new IllegalArgumentException("Node argument cannot be null");
        if (text == null)
            throw new IllegalArgumentException("Node text argument cannot be null");

        NodeList nl = n.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            if (nl.item(i).getNodeType() == Node.TEXT_NODE) {
                nl.item(i).setNodeValue(text);
                return;
            }
        }

        Node textNode = n.getOwnerDocument().createTextNode(text);
        n.appendChild(textNode);
    }
}