Java XML Element Create createElement(Document owner, String nsURI, String elementName, String textValue)

Here you can find the source of createElement(Document owner, String nsURI, String elementName, String textValue)

Description

Creates an Element object in the CyberSource namespace.

License

Open Source License

Parameter

Parameter Description
owner Document object to own the Element object.
nsURI Namespace URI to use.
elementName local name of Element object to create.
textValue text value of the new Element object.

Return

the newly created Element object.

Declaration

public static Element createElement(Document owner, String nsURI, String elementName, String textValue) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/* w  ww . j  a v  a2  s. c  o m*/
     * Creates an Element object in the CyberSource namespace.
     *
     * @param owner       Document object to own the Element object.
     * @param nsURI        Namespace URI to use.
     * @param elementName local name of Element object to create.
     * @param textValue   text value of the new Element object.
     * @return the newly created Element object.
     */
    public static Element createElement(Document owner, String nsURI, String elementName, String textValue) {
        Attr attr = owner.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns");
        attr.setValue(nsURI);
        Element elem = owner.createElementNS(nsURI, elementName);
        elem.setAttributeNodeNS(attr);

        elem.appendChild(owner.createTextNode(textValue));
        return (elem);
    }
}

Related

  1. createElement(Document document, String name, float value)
  2. createElement(Document document, String name, Map attributes, Element... children)
  3. createElement(Document document, String name, String textContent)
  4. createElement(Document dom, String elementName, Properties attributes)
  5. createElement(Document dom, String elementName, Properties attributes)
  6. createElement(Element parent, String elementName)
  7. createElement(Element parent, String name)
  8. createElement(Element parent, String name)
  9. createElement(Element parent, String path)