Java XML Node Remove removeElement(Element parent, String tagName)

Here you can find the source of removeElement(Element parent, String tagName)

Description

Remove the node from parent

License

Apache License

Parameter

Parameter Description
parent a parameter
tagName a parameter

Declaration

public static void removeElement(Element parent, String tagName) 

Method Source Code

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

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

public class Main {
    /**//  ww w .j  a va  2  s . co m
     * Remove the node from parent
     *
     * @param parent
     * @param tagName
     */
    public static void removeElement(Element parent, String tagName) {
        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);
            }
        }
    }
}

Related

  1. removeAll(final Node node, final short nodeType, final String name)
  2. removeAll(Node node)
  3. removeAll(Node node, short nodeType, String name)
  4. removeAll(Node node, short nodeType, String name)
  5. removeContents(Node parent)
  6. removeElements(Node parent, String nature)
  7. removeElementXML(Node node, short nodeType, String name)
  8. removeEmptyHeadings(Node root)
  9. removeEmptyHeadings(Node root)