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

voidremoveAttributes(Element element)
remove Attributes
NamedNodeMap namedNodeMap = element.getAttributes();
while (namedNodeMap.getLength() > 0) {
    element.removeAttributeNode((Attr) namedNodeMap.item(0));
voidremoveAttributes(Element target, boolean flag)
Drop the attributes from an element, except possibly an xmlns attribute that declares its namespace.
if (!target.hasAttributes()) {
    return;
String prefix = target.getPrefix();
NamedNodeMap nnm = target.getAttributes();
Attr toPutBack = null;
if (flag) {
    if (prefix == null) {
...
voidremoveAttributes(SOAPElement elem)
remove Attributes
if (elem.hasAttributes()) {
    Iterator attrNameIt = elem.getAllAttributes();
    while (attrNameIt.hasNext()) {
        Name attrName = (Name) attrNameIt.next();
        elem.removeAttribute(attrName);
ElementremoveDefaultNameSpaceAttributes(final Element element)
remove Default Name Space Attributes
Element ret = element;
ret.removeAttribute("xmlns:gmi");
ret.removeAttribute("xmlns:gco");
ret.removeAttribute("xmlns:gmd");
ret.removeAttribute("xmlns:gml");
ret.removeAttribute("xmlns:gmx");
ret.removeAttribute("xmlns:ows");
ret.removeAttribute("xmlns:xsi");
...
voidremoveEmptyAttributes(Element element)
Remove all attributes having an empty value.
NamedNodeMap attributes = element.getAttributes();
int attribCount = attributes.getLength();
for (int i = attribCount - 1; i >= 0; i--) {
    Attr attribute = (Attr) attributes.item(i);
    if (attribute.getValue().equals("")) {
        attributes.removeNamedItem(attribute.getName());
voidremoveInvalidAttributes(Element element, String... validAttributeNames)
remove Invalid Attributes
Set<String> validNames = new HashSet<String>();
for (String name : validAttributeNames) {
    validNames.add(name);
boolean elementModified = false;
NamedNodeMap nnm = element.getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
    String attributeName = nnm.item(i).getNodeName();
...
voidremoveNodeAttribute(Node node, String attributeName)
remove the given attribute from the given node based on the attribute's name
((Element) node).removeAttribute(attributeName);
voidremoveNodeAttribute(Node node, String name)
remove Node Attribute
if (node.hasAttributes()) {
    NamedNodeMap attrs = node.getAttributes();
    if (attrs.getNamedItem(name) != null) {
        attrs.removeNamedItem(name);
voidremoveNodeAttributes(Node node)
remove Node Attributes
NamedNodeMap attrs = node.getAttributes();
if ((attrs != null) && (attrs.getLength() > 0)) {
    String[] names = new String[attrs.getLength()];
    for (int i = 0; i < names.length; i++) {
        names[i] = attrs.item(i).getNodeName();
    for (int i = 0; i < names.length; i++) {
        attrs.removeNamedItem(names[i]);
...
voidremoveNodeContents(Node aSource, boolean aRemoveAttrs)
Removes the children and all attributes for the given source node.
if (aRemoveAttrs && aSource.hasAttributes()) {
    NamedNodeMap attrMap = aSource.getAttributes();
    int skip = 0;
    for (int i = 0, len = attrMap.getLength(); i < len; i++) {
        if (attrMap.item(skip).getNodeName().startsWith("xmlns:")) 
            skip++;
        else
            ((Element) aSource).removeAttribute(attrMap.item(skip).getNodeName());
...