Example usage for org.w3c.dom Document createElementNS

List of usage examples for org.w3c.dom Document createElementNS

Introduction

In this page you can find the example usage for org.w3c.dom Document createElementNS.

Prototype

public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException;

Source Link

Document

Creates an element of the given qualified name and namespace URI.

Usage

From source file:Main.java

public static Element addElement(Element parent, String childName, String textValue, Document doc) {
    Element childElement = doc.createElementNS(DEFAULT_NAMESPACE, childName);
    childElement.setTextContent(textValue);
    parent.appendChild(childElement);//w  w  w . j  a  va2  s .c om
    return childElement;
}

From source file:Main.java

public static Element addElement(Element parent, String childName, String attributeName, String attributeValue,
        Document doc) {
    Element childElement = doc.createElementNS(DEFAULT_NAMESPACE, childName);
    childElement.setAttribute(attributeName, attributeValue);
    parent.appendChild(childElement);/*  w  w  w.  j  a v a2s .  c o  m*/
    return childElement;
}

From source file:Main.java

/**
 * Create a new element in the parent node with the given local name and namespace.
 * @param parent The node to which the new element will be appended.
 * @param namespace The namespace of the new element to be created
 * @param name The local name of the new element to be created
 * @return The newly created element.//from  ww  w .j a v a  2s .c o m
 */
public static Element makeElementNS(Node parent, String namespace, String name) {
    Document d = getDoc(parent);
    Element result = d.createElementNS(namespace, name);
    parent.appendChild(result);
    return result;
}

From source file:Main.java

public static void edit(Document document) {
    String docNS = "http://www.my-company.com";

    Element order = document.createElementNS(docNS, "order");
    document.appendChild(order);//from ww w.j av  a2  s  .  com
    order.setAttribute("xmlns", docNS);
}

From source file:Main.java

/**
 * Adds an {@link Element} child to the given element.
 *
 * @param parent The {@link Element} to add the {@link Element} child to.
 * @param qualifiedName The fully qualified name of the new {@link Element}
 * child.//  w w w.ja  va  2s . c o  m
 * @return Returns the new {@link Element} child.
 */
public static Element addElementChildTo(Element parent, String nsURI, String qualifiedName) {
    final Document doc = parent.getOwnerDocument();
    final Element child = doc.createElementNS(nsURI, qualifiedName);
    parent.appendChild(child);
    return child;
}

From source file:Main.java

public static void addNode(Document doc, Node parent, String ns, String name, String text, Map NS_MAP) {
    Element child = doc.createElementNS((String) NS_MAP.get(ns), ns + ":" + name);
    child.appendChild(doc.createTextNode(text));
    parent.appendChild(child);//from w  ww .j ava  2  s.  c  om
}

From source file:Main.java

/**
 * Create a new element belonging to a namespace with specified text value.
 * //w  w  w. j a  v a 2s. c o  m
 * @param document
 * @param nodeName
 * @param textValue
 * @return created element
 */
public static Element createElementNS(Document document, String namespaceURI, String nodeName,
        String textValue) {
    Element element = document.createElementNS(namespaceURI, nodeName);
    Node textNode = document.createTextNode(textValue);
    element.appendChild(textNode);
    return element;
}

From source file:Main.java

/**
 * Criar um elemento XML//w  w w.j ava 2  s  .c o  m
 * @param doc -> Arquivo xml para assinatura
 * @param tag -> nome da tag para a qual sera gerado o elemento 
 * @param prefix -> prefixo do elemento
 * @param nsURI -> Uri da tag
 * @return Element ->  org.w3c.dom.Element
 * @see org.w3c.dom.Element
 */
public static Element criarElemento(Document doc, String tag, String prefix, String nsURI) {
    String qName = prefix == null ? tag : prefix + ":" + tag;
    return doc.createElementNS(nsURI, qName);
}

From source file:Main.java

/**
 * Adds a new element containing a CDATA section to the parent element
 * @param parent the parent element to add the new element to
 * @param namespaceURI the namespace of the added element's tag name, or null if there isn't any..
 * @param tag the tag name of the new element
 * @param text the text of the CDATA section (if text is null or empty no CDATA section will be added).
 *//*from  w ww .j  a v a2s  .c  o  m*/
public static void addTextElementNS(Element parent, String namespaceURI, String tag, String text) {

    // Add an element with the given tag name.
    Document document = parent.getOwnerDocument();
    Element textElement = namespaceURI != null ? document.createElementNS(namespaceURI, tag)
            : document.createElement(tag);
    parent.appendChild(textElement);

    if (text != null && text.length() > 0) {
        CDATASection cdata = createCDATASection(document, text);
        textElement.appendChild(cdata);
    }
}

From source file:Main.java

public static void encodeString(Document doc, Element parent, String str, String namespaceURI,
        String qualifiedName) {//from   ww  w.j  a  v  a2  s .  c om
    if (str != null) {
        Element elm = doc.createElementNS(namespaceURI, qualifiedName);
        Text strVal = doc.createTextNode(str);
        elm.appendChild(strVal);
        parent.appendChild(elm);
    }
}