Example usage for org.w3c.dom Element appendChild

List of usage examples for org.w3c.dom Element appendChild

Introduction

In this page you can find the example usage for org.w3c.dom Element appendChild.

Prototype

public Node appendChild(Node newChild) throws DOMException;

Source Link

Document

Adds the node newChild to the end of the list of children of this node.

Usage

From source file:Main.java

public static void addToXMLDoc(Document _doc, Element _element, String _tag, String _text) {
    Element child = _doc.createElement(_tag);
    _element.appendChild(child);
    Text childText = _doc.createTextNode(_text);
    child.appendChild(childText);/*from   www  . j av  a  2  s.  c om*/
}

From source file:Main.java

public static void addChildValue(Document doc, Node parent, String childName, String childValue) {
    Element element = doc.createElement(childName);
    Text text = doc.createTextNode(childValue);
    element.appendChild(text);
    parent.appendChild(element);//from  w  w  w . ja v  a 2 s  . c o m
}

From source file:Main.java

public static Element addTemplateNode(Document document, Element parent, String name) {
    Element element = document.createElement(TEMPLATE_NODE);
    parent.appendChild(element);
    element.setAttribute(NAME_ATTR, name);
    return element;
}

From source file:Main.java

public static Element addElement(Element root, String name) {
    Element newElement = root.getOwnerDocument().createElement(name);
    root.appendChild(newElement);
    return newElement;
}

From source file:Main.java

/**
 * create an element from a document, that has some text content in it
 * @param doc - document/*from w  w w .j  ava2s. c o  m*/
 * @param name - element name
 * @param attributes - attribute map
 * @param content - string content
 * @return element object
 */
public static Element createElement(Document doc, String name, Map<String, String> attributes, String content) {
    Element e = createElement(doc, name, attributes);
    e.appendChild(doc.createTextNode(content));
    return e;
}

From source file:Main.java

public static void writeStringValue(Document document, Element element, String elementValue) {
    Text textNode = document.createTextNode(elementValue);
    element.appendChild(textNode);
}

From source file:Main.java

/**
 * Creates ElementNode for given tag with particular text as content.
 *//*  w  w w  .  j av a2  s  . co  m*/
public static Element createTextNode(String tag, String content) throws ParserConfigurationException {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    Element node = doc.createElement(tag);
    Text t = doc.createTextNode(content);
    node.appendChild(t);

    return node;
}

From source file:Main.java

private static Element addPropertyNode(Document document, Element parent, String name) {
    Element element = document.createElement(PROPERTY_NODE);
    parent.appendChild(element);
    element.setAttribute(NAME_ATTR, name);
    return element;
}

From source file:Main.java

/**
 * Append application specific tags into xml signature document
 * @param document/*from   w w  w . j  av  a2  s. co m*/
 * @return
 */
public static Document addUserInfoToSignature(Document document) {

    Element signature = document.getDocumentElement();

    // initially it has no root-element, ... so we create it:
    Element root = document.createElement("digital-signature");

    Element subjInfo = document.createElement("subject-information");
    subjInfo.appendChild(document.createElement("subject"));
    subjInfo.appendChild(document.createElement("date"));
    subjInfo.appendChild(document.createElement("time"));
    subjInfo.appendChild(document.createElement("timestamp"));

    root.appendChild(subjInfo);
    root.appendChild(signature);
    // we can add an element to a document only once,
    // the following calls will raise exceptions:
    document.appendChild(root);
    document.setXmlStandalone(true);

    return document;
}

From source file:Main.java

public static void addTextElement(String name, String value, Element parent) {
    Element element = createTextElement(name, value, parent.getOwnerDocument());
    parent.appendChild(element);
}