Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;

public class Main {
    public static boolean updateTextNode(String nodeName, Element searchFrom, String data, int position)
            throws Exception {
        boolean result = false;
        Element currentElement = (Element) searchFrom.getElementsByTagName(nodeName).item(position);

        if (currentElement != null && currentElement.getNodeType() == Node.ELEMENT_NODE) {
            Text textNode = (Text) (currentElement.getFirstChild());
            textNode.setData(data);

            if (textNode != null && textNode.getNodeValue() == null)
                result = false;
            else
                result = true;
        }
        return result;
    }
}