private void addAttribute ( Element element , String attributeName , String attributeValue , String defaultValue ) { if ( attributeValue == null || attributeValue . equals ( defaultValue ) ) { Attribute attribute = ( Attribute ) element . selectSingleNode ( attributeName ) ; if ( attribute != null ) { element . remove ( attribute ) ; } } else { element . addAttribute ( attributeName , attributeValue ) ; } }
Adds the attribute to the element if the attributeValue is not equal to defaultValue . If attributeValue is null or equals defaultValue remove the attribute from the element if it is present .