Java Utililty Methods XML Node Remove

List of utility methods to do XML Node Remove

Description

The list of methods to do XML Node Remove are organized into topic(s).

Method

voidremoveNode(Node node)
Removes a node from its tree.
node.getParentNode().removeChild(node);
voidremoveNode(Node node)
remove Node
if (node != null) {
    Node parent = node.getParentNode();
    if (parent != null) {
        parent.removeChild(node);
voidremoveNode(Node node)
remove Node
node.getParentNode().removeChild(node);
voidremoveNodeFromParent(Node node)
remove Node From Parent
Node parent = node.getParentNode();
parent.removeChild(node);
voidremoveNodes(Element parent, NodeList elements)
remove Nodes
List<Node> nodesToRemove = new ArrayList<Node>();
for (int i = 0; i < elements.getLength(); i++) {
    Node item = elements.item(i);
    if (item.getParentNode() == parent) {
        nodesToRemove.add(item);
for (Node n : nodesToRemove) {
...
voidremoveNodesByName(Node node, String name)
remove Nodes By Name
NodeList nl = node.getChildNodes();
int i = 0;
while (i < nl.getLength())
    if (nl.item(i).getNodeName().equals(name))
        node.removeChild(nl.item(i));
    else
        i++;
voidremovePreviousWhiteSpace(Node node)
remove Previous White Space
Node prev = node.getPreviousSibling();
if (prev != null && prev.getNodeType() == Node.TEXT_NODE && prev.getNodeValue().trim().length() == 0) {
    node.getParentNode().removeChild(prev);
NoderemoveQueryCallBody(Node queryElement)
remove Query Call Body
if ("QueryRequest".equals(queryElement.getNodeName())) {
    return queryElement.getFirstChild().getFirstChild();
return null;
NoderemoveSelf(Node node)
delete a Node which was appointed in an argument.
if (node == null)
    return null;
Node pNode = node.getParentNode();
if (pNode != null) {
    return pNode.removeChild(node);
return null;
NoderemoveTextNodes(Node parent)
Removes all the immediate child text nodes.
Node result = parent;
NodeList nodeList = parent.getChildNodes();
int nodeListSize = nodeList.getLength();
for (int i = 0; i < nodeListSize; i++) {
    Node child = nodeList.item(i);
    if (child != null && child.getNodeType() == Node.TEXT_NODE) {
        parent.removeChild(child);
return result;