Java XML Attribute Remove removeAllSubNodesExceptAttributes(Node n)

Here you can find the source of removeAllSubNodesExceptAttributes(Node n)

Description

remove All Sub Nodes Except Attributes

License

Open Source License

Declaration

public static void removeAllSubNodesExceptAttributes(Node n) 

Method Source Code

//package com.java2s;
/**/*from   w w w.  java 2 s  .  c om*/
 * This file belongs to the BPELUnit utility and Eclipse plugin set. See enclosed
 * license file for more information.
 */

import java.util.ArrayList;
import java.util.List;

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

public class Main {
    public static void removeAllSubNodesExceptAttributes(Node n) {
        NodeList childNodes = n.getChildNodes();
        List<Node> childNodesToRemove = new ArrayList<Node>();

        for (int i = 0; i < childNodes.getLength(); i++) {
            Node c = childNodes.item(i);

            if (c.getNodeType() != Node.ATTRIBUTE_NODE) {
                childNodesToRemove.add(c);
            }
        }

        for (Node c : childNodesToRemove) {
            n.removeChild(c);
        }
    }
}

Related

  1. removeAllAttributes(Element element)
  2. removeAllAttributes(Element element)
  3. removeAllAttributes(Element element)
  4. removeAllAttributes(Node node, String attrName)
  5. removeAttribute(Element elem, String name)
  6. removeAttribute(Element element, String name)
  7. removeAttribute(final Attr attributeNode)
  8. removeAttribute(final Node iNode, final String iAttributeName)