Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.apache.log4j.Logger;

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

public class Main {
    static Logger logger = Logger.getLogger("XmlOper");

    public static void removeElement(Element parent, String tagName) {
        logger.debug("remove " + parent.getNodeName() + "'s children by tagName " + tagName + " begin...");
        NodeList nl = parent.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node nd = nl.item(i);
            if (nd.getNodeName().equals(tagName)) {
                parent.removeChild(nd);
                logger.debug("remove child '" + nd + "' success.");
            }
        }
        logger.debug("remove " + parent.getNodeName() + "'s children by tagName " + tagName + " end.");
    }
}