Java XML Attribute Remove removeAttributes(Element e, String namespaceURI)

Here you can find the source of removeAttributes(Element e, String namespaceURI)

Description

Remove all attributes with a certain namespace from this element.

License

Apache License

Parameter

Parameter Description
element Element whose attributes we want to remove.
namespaceURI Namespace URI of the attributes to remove.

Declaration


public static void removeAttributes(Element e, String namespaceURI) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Element;
import org.w3c.dom.Attr;

import org.w3c.dom.NamedNodeMap;
import java.util.ArrayList;

import java.util.Iterator;

public class Main {
    /** Remove all attributes with a certain namespace from this element.
         //from   w  w  w  . ja  v  a 2 s .c o m
    @param element Element whose attributes we want to remove.
    @param namespaceURI Namespace URI of the attributes to remove. */

    public static void removeAttributes(Element e, String namespaceURI) {
        NamedNodeMap attributes = e.getAttributes();
        ArrayList list = new ArrayList();
        for (int i = 0; i < attributes.getLength(); i++) {
            Attr a = (Attr) attributes.item(i);
            if (namespaceURI.equals(a.getNamespaceURI())) {
                list.add(a);
            }
        }

        Iterator i = list.iterator();
        while (i.hasNext()) {
            e.removeAttributeNode((Attr) i.next());
        }
    }
}

Related

  1. removeAttribute(Node node, String attr)
  2. removeAttribute(Node node, String attrName)
  3. removeAttribute(Node node, String... attributs)
  4. removeAttribute(Node parent, String name, String value, boolean recursive)
  5. removeAttributeIgnoreCase(Element element, String attributeName)
  6. removeAttributes(Element elem)
  7. removeAttributes(Element element)
  8. removeAttributes(Element target, boolean flag)
  9. removeAttributes(SOAPElement elem)