Java XML Attribute Remove removeAllAttributes(Element element)

Here you can find the source of removeAllAttributes(Element element)

Description

remove All Attributes

License

Open Source License

Declaration

public static void removeAllAttributes(Element element) 

Method Source Code


//package com.java2s;
/*/*from   w w  w . j av a2 s . c o  m*/
 * Copyright (c) 2004-2012 The YAWL Foundation. All rights reserved.
 * The YAWL Foundation is a collaboration of individuals and
 * organisations who are committed to improving workflow technology.
 *
 * This file is part of YAWL. YAWL is free software: you can
 * redistribute it and/or modify it under the terms of the GNU Lesser
 * General Public License as published by the Free Software Foundation.
 *
 * YAWL 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. See the GNU Lesser General
 * Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with YAWL. If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.*;

import java.util.Vector;

public class Main {
    public static void removeAllAttributes(Element element) {
        Vector<String> names = new Vector<String>();

        int length = element.getAttributes().getLength();
        NamedNodeMap atts = element.getAttributes();

        for (int i = 0; i < length; names.add(atts.item(i).getLocalName()), i++)
            ;

        for (String name : names)
            element.removeAttribute(name);
    }
}

Related

  1. removeAllAttributes(Element element)
  2. removeAllAttributes(Element element)
  3. removeAllAttributes(Node node, String attrName)
  4. removeAllSubNodesExceptAttributes(Node n)