append Collection to XML Node as attribute - Java XML

Java examples for XML:XML Attribute

Description

append Collection to XML Node as attribute

Demo Code


//package com.java2s;
import java.util.Collection;

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    public static void appendCollection(Node node, Collection c, String tag) {
        appendCollection(node, c.toArray(), tag);
    }/*from  w  w  w  .j  a v  a2 s .c  o  m*/

    public static void appendCollection(Node node, Object[] o, String tag) {
        Element child = node.getOwnerDocument().createElement(tag);
        for (int i = 0; i < o.length; i++) {
            child.setAttribute("element_" + i, (String) o[i]);
        }
        node.appendChild(child);
    }
}

Related Tutorials