Java XML Attribute Add addAttribute(Document doc, Node parentNode, String name, String content)

Here you can find the source of addAttribute(Document doc, Node parentNode, String name, String content)

Description

add Attribute

License

Open Source License

Declaration

public static void addAttribute(Document doc, Node parentNode, String name, String content) 

Method Source Code

//package com.java2s;
/*//from   w w  w.  j  av a  2 s  . co m
 * Keystone Development Framework
 * Copyright (C) 2004-2009 Rick Knowles
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License
 * Version 2 as published by the Free Software Foundation.
 *
 * This program 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 Version 2 for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * Version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import org.w3c.dom.Attr;
import org.w3c.dom.Document;

import org.w3c.dom.Node;

public class Main {
    public static void addAttribute(Document doc, Node parentNode, String name, String content) {
        Attr attNode = doc.createAttribute(name);
        attNode.setNodeValue(content);
        parentNode.getAttributes().setNamedItem(attNode);
    }
}

Related

  1. addArrayOffsetAttribute(Element element, int offset)
  2. addAttrDirect(Map values, Element el)
  3. addAttribute(Document doc, Element node, String name, String value)
  4. addAttribute(Document doc, Element node, String name, String value)
  5. addAttribute(Document doc, Element parent, String attribute, Object value)
  6. addAttribute(Document doc, org.w3c.dom.Element e, String index, String value)
  7. addAttribute(Document doc, String name, Element e, String value)
  8. addAttribute(Document document, Node node, String attName, String attValue)
  9. addAttribute(Document document, Node node, String name, String value)