Example usage for org.w3c.dom Node removeChild

List of usage examples for org.w3c.dom Node removeChild

Introduction

In this page you can find the example usage for org.w3c.dom Node removeChild.

Prototype

public Node removeChild(Node oldChild) throws DOMException;

Source Link

Document

Removes the child node indicated by oldChild from the list of children, and returns it.

Usage

From source file:Main.java

/***
 * Remove all children nodes//www.  j  a  v a2  s.  co m
 * 
 * @param node
 *            node to remove children from
 * 
 */
public static void removeAllChilden(final Node node) {
    if (node != null) {
        final NodeList childrens = node.getChildNodes();

        for (int i = 0; i < childrens.getLength(); i++) {
            node.removeChild(childrens.item(i));
        }
    }
}

From source file:Main.java

public static void removeChildNodes(Node node) {
    NodeList nl = node.getChildNodes();

    //for (int i = 0; i < nl.getLength(); i++) 
    while (nl.getLength() > 0)
        node.removeChild(nl.item(0));

}

From source file:Main.java

public static void removeChildren(Node node) {
    NodeList children = node.getChildNodes();
    if (children != null) {
        int len = children.getLength();
        for (int i = len - 1; i >= 0; i--) {
            node.removeChild(children.item(i));
        }/*  ww w  .j av  a  2 s . c  o m*/
    }
}

From source file:Main.java

/**
 * @param node/*  ww w.j a v a 2 s.com*/
 */
public static void removeChildNodes(Node node, short... ignoreNodeTypes) {
    HashSet<Node> childNodesSet = getValidChildNodes(node, false, ignoreNodeTypes);
    for (Node childNode : childNodesSet) {
        node.removeChild(childNode);
    }
}

From source file:Main.java

public static void removeNode(Document doc, Node parent, Node node, String nodeName) {
    Node comment = doc.createComment(" '" + nodeName + "' was removed by FM GUI @ " + (new Date()) + " ");
    parent.insertBefore(comment, node);/*from ww w.j  a va  2 s  .co  m*/
    parent.removeChild(node);
}

From source file:Main.java

public static void removeTextNodes(Node node) {
    NodeList nl = node.getChildNodes();

    int i = 0;//from   w  ww  . j  av  a  2s.c om
    while (i < nl.getLength())
        if (nl.item(i).getNodeType() == Node.TEXT_NODE)
            node.removeChild(nl.item(i));
        else
            i++;
}

From source file:Main.java

public static void removeNodesByName(Node node, String name) {
    NodeList nl = node.getChildNodes();

    int i = 0;//from   w  w w.  j  a  va  2s .  c  o  m
    while (i < nl.getLength())
        if (nl.item(i).getNodeName().equals(name))
            node.removeChild(nl.item(i));
        else
            i++;
}

From source file:Main.java

/**
 * Remove all children with specified name from the specified node
 */// w w  w. j a va2 s .  com
public static void removeChildren(Node node, String name) {
    Node currentChild = node.getFirstChild();

    while (currentChild != null) {
        final Node nextChild = currentChild.getNextSibling();

        if (currentChild.getNodeName().equals(name))
            node.removeChild(currentChild);

        currentChild = nextChild;
    }
}

From source file:com.wavemaker.tools.ws.XJCCompiler.java

private static Element removeImportElement(Element element) {
    NodeList nodeList = element.getElementsByTagNameNS(Constants.XSD_NS, "import");
    if (nodeList.getLength() == 0) {
        return element; // simply returns the original one
    }/*from   w w  w .  ja  v a  2s .  c  o m*/

    // do a clone since we are going to remove the import stuffs from the
    // element
    Element elementClone = (Element) element.cloneNode(true);
    nodeList = elementClone.getElementsByTagNameNS(Constants.XSD_NS, "import");
    List<Node> ns = new ArrayList<Node>();
    for (int tmp = 0; tmp < nodeList.getLength(); tmp++) {
        Node importNode = nodeList.item(tmp);
        ns.add(importNode);
    }
    for (Node item : ns) {
        Node schemaNode = item.getParentNode();
        schemaNode.removeChild(item);
    }
    return elementClone;
}

From source file:Main.java

public static Node addNode(Document doc, Node parent, String name) {
    Node child = null;//  www  .jav a  2  s . co m
    try {
        child = doc.createElement(name);
        return parent.appendChild(child);
    } catch (DOMException ex) {
        try {
            if (child != null)
                parent.removeChild(child);
        } catch (DOMException ex2) {
        }
        return null;
    }
}