Here you can find the source of removeAttributes(Element e, String namespaceURI)
Parameter | Description |
---|---|
element | Element whose attributes we want to remove. |
namespaceURI | Namespace URI of the attributes to remove. |
public static void removeAttributes(Element e, String namespaceURI)
//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()); } } }