Java XML Attribute Set setAttribute(Node n, String name, String value)

Here you can find the source of setAttribute(Node n, String name, String value)

Description

set Attribute

License

Open Source License

Declaration

public static boolean setAttribute(Node n, String name, String value) 

Method Source Code

//package com.java2s;
/* Copyright (c) 2011 by crossmobile.org
 *
 * CrossMobile is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.
 *
 * CrossMobile is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with CrossMobile; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *///from   w  w  w. j a  va  2s. co  m

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    public static boolean setAttribute(Node n, String name, String value) {
        if (value == null)
            return deleteAttribute(n, name);
        if (n == null || name == null || value == null)
            return false;
        if (n instanceof Element) {
            ((Element) n).setAttribute(name, value);
            return true;
        }
        return false;
    }

    public static boolean deleteAttribute(Node n, String name) {
        if (n == null || name == null)
            return false;
        if (n instanceof Element) {
            ((Element) n).removeAttribute(name);
            return true;
        }
        return false;
    }
}

Related

  1. setAttribute(Element element, String attrName, Object value)
  2. setAttribute(Element element, String name, String value)
  3. setAttribute(Element targetElem, String name, String value)
  4. setAttribute(final Element element, final String attrName, final Object value)
  5. setAttribute(final Element element, final String name, final String value)
  6. setAttribute(Node node, String attName, String val)
  7. setAttribute(Node node, String attr, String value)
  8. setAttribute(Node node, String key, String value)
  9. setAttribute(Node pNode, String attrName)