Java Utililty Methods XML Attribute Remove

List of utility methods to do XML Attribute Remove

Description

The list of methods to do XML Attribute Remove are organized into topic(s).

Method

voidremoveAllAttributes(Element element)
remove All Attributes
NamedNodeMap attrs = element.getAttributes();
int attrCount = attrs.getLength();
for (int i = attrCount - 1; i >= 0; --i) {
    Attr attr = (Attr) attrs.item(i);
    attrs.removeNamedItemNS(attr.getNamespaceURI(), attr.getLocalName());
voidremoveAllAttributes(Element element)
remove All Attributes
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);
voidremoveAllAttributes(Element element)
Remove all attribute from the specified element
final NamedNodeMap nodeMap = element.getAttributes();
for (int i = 0; i < nodeMap.getLength(); i++)
    element.removeAttribute(nodeMap.item(i).getNodeName());
voidremoveAllAttributes(Node node, String attrName)
remove All Attributes
NamedNodeMap attrs = node.getAttributes();
if (attrs != null && attrs.getNamedItem(attrName) != null) {
    attrs.removeNamedItem(attrName);
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node childNode = list.item(i);
    removeAllAttributes(childNode, attrName);
...
voidremoveAllSubNodesExceptAttributes(Node n)
remove All Sub Nodes Except Attributes
NodeList childNodes = n.getChildNodes();
List<Node> childNodesToRemove = new ArrayList<Node>();
for (int i = 0; i < childNodes.getLength(); i++) {
    Node c = childNodes.item(i);
    if (c.getNodeType() != Node.ATTRIBUTE_NODE) {
        childNodesToRemove.add(c);
for (Node c : childNodesToRemove) {
    n.removeChild(c);
voidremoveAttribute(Element elem, String name)
Oracle 10i does not allow to remove an attribute that does not exist.
try {
    elem.removeAttribute(name);
} catch (Exception e) {
voidremoveAttribute(Element element, String name)
Remove an attribute from the specified element
element.removeAttribute(name);
voidremoveAttribute(final Attr attributeNode)
remove Attribute
if (attributeNode == null) {
    return;
final Element owner = attributeNode.getOwnerElement();
if (owner == null) {
    return;
owner.removeAttributeNode(attributeNode);
...
voidremoveAttribute(final Node iNode, final String iAttributeName)
This method removes the specified attribute from the specified node.
NamedNodeMap attrList = iNode.getAttributes();
attrList.removeNamedItem(iAttributeName);
voidremoveAttribute(final Node node, final String name)
remove Attribute
if (node != null) {
    final NamedNodeMap namedNodeMap = node.getAttributes();
    if (namedNodeMap != null) {
        namedNodeMap.removeNamedItem(name);