Java XML Attribute Create writeOutAttributesForNode(String[][] attributes, Node node)

Here you can find the source of writeOutAttributesForNode(String[][] attributes, Node node)

Description

write Out Attributes For Node

License

Open Source License

Declaration

public static void writeOutAttributesForNode(String[][] attributes, Node node) 

Method Source Code

//package com.java2s;
/*//from w  w  w  . j a  va2s.  com
 * 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 java.util.Iterator;

import java.util.Map;

import org.w3c.dom.Attr;

import org.w3c.dom.Node;

public class Main {
    public static void writeOutAttributesForNode(Map<?, ?> attributes, Node node) {
        if (attributes != null) {
            // Add attributes
            for (Iterator<?> i = attributes.keySet().iterator(); i.hasNext();) {
                Object key = i.next();
                Object value = attributes.get(key);
                if ((key != null) && (value != null)) {
                    Attr attNode = node.getOwnerDocument().createAttribute(key.toString());
                    attNode.setNodeValue(value.toString());
                    node.getAttributes().setNamedItem(attNode);
                }
            }
        }
    }

    public static void writeOutAttributesForNode(String[][] attributes, Node node) {
        if (attributes != null) {
            // Add attributes
            for (int n = 0; n < attributes.length; n++) {
                String key = attributes[n][0];
                String value = attributes[n][1];
                if ((key != null) && (value != null)) {
                    Attr attNode = node.getOwnerDocument().createAttribute(key.toString());
                    attNode.setNodeValue(value.toString());
                    node.getAttributes().setNamedItem(attNode);
                }
            }
        }
    }
}

Related

  1. writeAttribute(XMLStreamWriter writer, String name, Object value)
  2. writeAttribute(XMLStreamWriter xmlw, String name, String value)
  3. writeAttributeEvent(XMLEvent event, XMLStreamWriter writer)
  4. writeAttributes(Node node, Writer out)
  5. writeBoolAttr(Element element, String attributeName, boolean value)
  6. writeSvgAttributes(XMLStreamWriter w, Supplier cssClass, Supplier fill, Supplier stroke)
  7. writeXmlAttribute(XMLStreamWriter out, String name, Date value)