Java XML Attribute Add addAttribute(final AttributesImpl attributes, final String localName, final Object value)

Here you can find the source of addAttribute(final AttributesImpl attributes, final String localName, final Object value)

Description

Adds attribute with localName to attributes if value is not null.

License

Open Source License

Parameter

Parameter Description
attributes to add to.
localName of attribute to add.
value to add to attribute.

Declaration

static public void addAttribute(final AttributesImpl attributes, final String localName, final Object value) 

Method Source Code


//package com.java2s;
import javax.xml.XMLConstants;

import org.xml.sax.helpers.AttributesImpl;

public class Main {
    /**/*from w  w  w .  j  av a2s  . c  om*/
     * Adds attribute with <code>localName</code> to <code>attributes</code> if
     * value is not null. Follows the same rules as
     * {@link AttributesImpl#addAttribute(String, String, String, String, String)}
     * .
     * 
     * @param attributes
     *          to add to.
     * @param localName
     *          of attribute to add.
     * @param value
     *          to add to attribute.
     * @since 8.1
     */
    static public void addAttribute(final AttributesImpl attributes, final String localName, final Object value) {
        if (null != value) {
            attributes.addAttribute(XMLConstants.NULL_NS_URI, localName, localName, "", value.toString());
        }
    }

    /**
     * Adds attribute with <code>prefix</code> and <code>localName</code> to
     * <code>attributes</code> if value is not null. Follows the same rules as
     * {@link AttributesImpl#addAttribute(String, String, String, String, String)}
     * .
     * 
     * @param attributes
     *          to add to.
     * @param prefix
     *          of the attribute.
     * @param localName
     *          of attribute to add.
     * @param value
     *          to add to attribute.
     * @since 8.1
     */
    static public void addAttribute(final AttributesImpl attributes, final String prefix, final String localName,
            final Object value) {
        if (null != value) {
            attributes.addAttribute(XMLConstants.NULL_NS_URI, localName, prefix + ":" + localName, "",
                    value.toString());
        }
    }
}

Related

  1. addAttribute(Document document, Node node, String name, String value)
  2. addAttribute(Document document, String AttribName, String attribValue, Element element)
  3. addAttribute(Document xmlDoc, Node node, String attrName, String attrValue)
  4. addAttribute(Element el, String name, String val)
  5. addAttribute(Element elem, String name, String value)
  6. addAttribute(final Document doc, final Element parent, final String name, final String value)
  7. addAttribute(final Element element, final String attributeName, final String value)
  8. addAttribute(final Node e, final String name, final String value)
  9. addAttribute(final Node node, final Attr attribute)