Java examples for XML:XML Element Parent
Remove the node from parent XML Element
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from w w w. j av a2s . c o 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); } } } }