Java XML Attribute Remove removeAttributes(Element elem)

Here you can find the source of removeAttributes(Element elem)

Description

remove Attributes

License

Open Source License

Declaration

public static void removeAttributes(Element elem) 

Method Source Code

//package com.java2s;
/*// w ww . jav a 2s.c o  m
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
 * published by JBoss Inc.; either version 1.0 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

import org.w3c.dom.Attr;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

public class Main {
    public static void removeAttributes(Element elem) {
        if (elem.hasAttributes()) {
            NamedNodeMap attributeMap = elem.getAttributes();
            // since node maps are live, hold attributes in a separate collection
            int n = attributeMap.getLength();
            Attr[] attributes = new Attr[n];
            for (int i = 0; i < n; i++)
                attributes[i] = (Attr) attributeMap.item(i);
            // now remove each attribute from the element
            for (int i = 0; i < n; i++)
                elem.removeAttributeNode(attributes[i]);
        }
    }
}

Related

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