Java XML Child Element Create createAndAppendChild(Element parentElement, String elementName, Properties attributes)

Here you can find the source of createAndAppendChild(Element parentElement, String elementName, Properties attributes)

Description

create And Append Child

License

Open Source License

Declaration

public static Element createAndAppendChild(Element parentElement, String elementName, Properties attributes) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:// w w w.  j  av a2  s .  c  o  m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.Enumeration;
import java.util.Properties;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Main {
    public static Element createAndAppendChild(Element parentElement, String elementName, Properties attributes) {

        Element element = createElement(parentElement.getOwnerDocument(), elementName, attributes);
        parentElement.appendChild(element);
        return element;
    }

    public static Element createElement(Document dom, String elementName, Properties attributes) {

        // make sure to create element with any namespace uri to enable finding
        // it again using Dom.getElementsByTagNameNS()
        Element element = dom.createElementNS("", elementName); //$NON-NLS-1$
        if (attributes != null) {
            Enumeration e = attributes.keys();
            while (e.hasMoreElements()) {
                String key = (String) e.nextElement();
                element.setAttribute(key, attributes.getProperty(key));
            }
        }
        return element;
    }
}

Related

  1. addElement(final Document dom, final Element el, final String name, final String value)
  2. addElementAndSetContent(Document doc, String name, Element parent, String text)
  3. addElementChildToElement(Document doc, Element parent, String elementName)
  4. addElementWithText(Document document, Element parentElement, String newElementName, String textString)
  5. appendDateNode(Document owner, Element appendElement, String name, Date date)
  6. createChild(Document document, Node parent, String childNodeName)
  7. createChild(Element el, String name, boolean attach)
  8. createChild(final Element el, final String name)
  9. createChild(Node node, String elemName)