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

public static void removeChilds(Node node) {
    NodeList nl = node.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++)
        node.removeChild(nl.item(i));
}

From source file:Main.java

public static boolean removeNode(Node parent, Node child) {
    if (parent == null || child == null)
        return false;
    try {/*  ww w  .  ja  v  a  2s.  c  o  m*/
        parent.removeChild(child);
        return true;
    } catch (DOMException ex) {
        return false;
    }
}

From source file:Main.java

public static void removeChildren(Node e) {
    NodeList list = e.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        Node n = list.item(i);//w ww  .  ja  va 2 s  . c  o m
        e.removeChild(n);
    }
}

From source file:com.cloudseal.spring.client.namespace.Utility.java

public static void removeNode(final Element rootElement, final String xPathLocation)
        throws XPathExpressionException {
    final XPath xPath = XPathFactory.newInstance().newXPath();
    xPath.setNamespaceContext(new CloudSealNamespaceContext());
    final Node node = (Node) xPath.evaluate(xPathLocation, rootElement, XPathConstants.NODE);
    final short nodeType = node.getNodeType();

    switch (nodeType) {
    case Node.ELEMENT_NODE:
        final Node parent = node.getParentNode();
        parent.removeChild(node);
        break;/*from w  w  w .  j  a  v a2  s  .  c  om*/

    case Node.ATTRIBUTE_NODE:
        final Attr attribute = (Attr) node;
        final Element element = attribute.getOwnerElement();
        element.removeAttributeNode(attribute);
        break;

    default:
        throw new IllegalArgumentException("Not supported node type: " + nodeType);
    }
}

From source file:Main.java

public static void removeChildren(Node node) {
    NodeList childNodes = node.getChildNodes();
    int length = childNodes.getLength();
    for (int i = length - 1; i > -1; i--)
        node.removeChild(childNodes.item(i));
}

From source file:Main.java

public static void removeChildren(Node node) {
    NodeList childNodes = node.getChildNodes();
    int length = childNodes.getLength();
    for (int i = length - 1; i > -1; i--) {
        node.removeChild(childNodes.item(i));
    }/*from w w w  .j  a v  a  2 s  . c o  m*/
}

From source file:Main.java

/**
 * Removes all children nodes with the specific name of the given node
 * @param node/*  w w w. ja  v a2 s. c om*/
 */
public static void removeChildren(Node node, String name) {
    if (node == null)
        return;

    for (Node item : getChildrenByTagName(node, name)) {
        node.removeChild(item);
    }
}

From source file:Main.java

public static void removeChildNodes(Node node) {
    for (Node current = node.getFirstChild(), next; current != null; current = next) {
        next = current.getNextSibling();
        node.removeChild(current);
    }/*from   ww w .j  a v  a2s  .  c  o  m*/
}

From source file:Main.java

public static void removeChildren(Node parent) {
    for (;;) {/*from  w w w. jav a2  s  . co m*/
        Node n = parent.getFirstChild();

        if (n == null) {
            break;
        }

        parent.removeChild(n);
    }
}

From source file:Main.java

public static void replaceText(Node node, String text) {
    for (;;) {//from w w  w.  j  av  a  2  s . c  o m
        Node n = node.getFirstChild();
        if (n == null) {
            break;
        }
        node.removeChild(n);
    }
    Text t = node.getOwnerDocument().createTextNode(text);
    node.appendChild(t);
}