Java XML Attribute Remove removeAttribute(Node parent, String name, String value, boolean recursive)

Here you can find the source of removeAttribute(Node parent, String name, String value, boolean recursive)

Description

remove Attribute

License

Open Source License

Declaration

public static void removeAttribute(Node parent, String name, String value, boolean recursive) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    public static void removeAttribute(Node parent, String name, String value, boolean recursive) {
        NamedNodeMap nnm = parent.getAttributes();
        if (nnm != null)
            if (value == null)
                nnm.removeNamedItem(name);
            else {
                Node attr = nnm.getNamedItem(name);
                if (attr != null) {
                    String attrVal = attr.getNodeValue();
                    if (value.equals(attrVal))
                        nnm.removeNamedItem(name);
                }//  w  w w . ja  v  a2  s .  c  o  m
            }
        if (recursive)
            for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling())
                removeAttribute(child, name, value, recursive);
    }
}

Related

  1. removeAttribute(Node iNode, String iAttributeName)
  2. removeAttribute(Node node, String attName)
  3. removeAttribute(Node node, String attr)
  4. removeAttribute(Node node, String attrName)
  5. removeAttribute(Node node, String... attributs)
  6. removeAttributeIgnoreCase(Element element, String attributeName)
  7. removeAttributes(Element e, String namespaceURI)
  8. removeAttributes(Element elem)
  9. removeAttributes(Element element)