Java XML Attribute Append appendAttributeIfNotNull(Element parentElement, String attributeName, Object attributeValue)

Here you can find the source of appendAttributeIfNotNull(Element parentElement, String attributeName, Object attributeValue)

Description

append Attribute If Not Null

License

Apache License

Declaration

public static void appendAttributeIfNotNull(Element parentElement, String attributeName,
            Object attributeValue) 

Method Source Code

//package com.java2s;
/*//w w  w.  j a v a 2s .  c o m
 * Copyright 2013 Christian Robert
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.w3c.dom.Element;

public class Main {
    public static void appendAttributeIfNotNull(Element parentElement, String attributeName,
            Object attributeValue) {
        if (attributeValue != null) {
            parentElement.setAttribute(attributeName, attributeValue.toString());
        }
    }
}

Related

  1. appendAllAttributes(Node node, StringBuffer xpath)
  2. appendAttribute(Node node, String name, String value)
  3. appendAttributeNode(String namespace, Element parent, String name, String value)
  4. appendAttributes(Node node, StringBuffer sb)
  5. appendBooleanAttribute(Element thisElement, String attrName, boolean value)
  6. appendBooleanElement(Element parentElement, String nodeName, boolean value)