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:net.sf.jabref.exporter.OOCalcDatabase.java

private static void addTableCell(Document doc, Element parent, String content) {
    Element cell = doc.createElement("table:table-cell");
    Element text = doc.createElement("text:p");
    Text textNode = doc.createTextNode(content);
    text.appendChild(textNode);
    //text.setTextContent(content);
    cell.appendChild(text);/*  w  w w.  ja va 2s.  com*/
    parent.appendChild(cell);
}

From source file:Main.java

/**
 * Add an element to a parent element with its value.
 * @param doc DOM document object/*from   w ww .  ja  v  a 2  s  . c  om*/
 * @param parentElement parent element
 * @param elementName name of the element
 * @param value text of the element
 */
public static void addTagValue(final Document doc, final Element parentElement, final String elementName,
        final String value) {

    if (doc == null || parentElement == null || elementName == null || value == null) {
        return;
    }

    Element child = doc.createElement(elementName);
    parentElement.appendChild(child);
    child.appendChild(doc.createTextNode(value));
}

From source file:fr.aliasource.webmail.server.proxy.client.http.DOMUtils.java

public static Element createElement(Element parent, String elementName) {
    Element el = parent.getOwnerDocument().createElement(elementName);
    parent.appendChild(el);
    return el;//from   w w w .j a  v  a2  s .c  o  m
}

From source file:com.twentyn.patentExtractor.Util.java

public static Document nodeToDocument(DocumentBuilder docBuilder, String documentContainer, Node n) {
    /* With help from://  w w w  .jav a2 s  .  c o m
     * http://examples.javacodegeeks.com/core-java/xml/dom/copy-nodes-subtree-from-one-dom-document-to-another/ */
    org.w3c.dom.Document newDoc = docBuilder.newDocument();
    Element rootElement = newDoc.createElement(documentContainer);
    Node newNode = newDoc.importNode(n, true);
    rootElement.appendChild(newNode);
    newDoc.appendChild(rootElement);
    return newDoc;
}

From source file:Main.java

public static void addFragment(Document doc) {
    Element person;/*from  ww w.j  av  a2 s .  c  o  m*/
    Element root = doc.getDocumentElement();
    DocumentFragment fragment = doc.createDocumentFragment();
    person = makePersonNode(doc, "Name 1", "555-4444");
    fragment.appendChild(person);
    person = makePersonNode(doc, "Name 2", "555-9999");
    fragment.appendChild(person);
    root.appendChild(fragment);
}

From source file:it.unitn.disi.smatch.webapi.model.JSONHelper.java

public static Document wrapJsonToXml(JSONObject obj) throws ParserConfigurationException {
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Element root = doc.createElement(TAG_WEBAPI);
    Element el = doc.createElement(TAG_JSON_DATA);
    Text txt = doc.createTextNode(obj.toString());
    el.appendChild(txt);
    root.appendChild(el);//from   ww  w  .  j a v  a2s .  co  m
    doc.appendChild(root);
    return doc;
}

From source file:Main.java

/**
 * adds an Element with one attribut to a DOM-tree.
 * /*  w  w w  . ja  v  a 2 s.  c  o  m*/
 * @param document
 *            Document: the DOM-tree to add to
 * @param father
 *            Element: the new element will be inserted directly under this
 *            Element in the tree
 * @param name
 *            String: the name of the new element
 * @param attOneName
 *            String: the name of the attribut
 * @param attOneValue
 *            String: the value of the attribut
 */
public static void addElement(Document document, Element father, String name, String attOneName,
        String attOneValue) {
    Element element = document.createElement(name);
    element.setAttribute(attOneName, attOneValue);
    father.appendChild(element);
}

From source file:Main.java

public static void createElementAndAppend(String name, Date value, Document doc, Element appendeeElement,
        String attributeName, String attributeValue) {
    Element newElement = null;
    if (value == null) {

        log.info("XMLUtil.createElementAndAppend()  value == null for name = " + name);
        newElement = doc.createElement(name);
        Text text = doc.createTextNode("");
        newElement.appendChild(text);
    } else {/*from   ww  w.  j ava  2 s  .co m*/
        newElement = doc.createElement(name);
        Text text = doc.createTextNode(sdfObj.format(value));
        newElement.appendChild(text);
    }
    if (attributeName != null && !attributeName.equals("")) {
        newElement.setAttribute(attributeName, attributeValue);
    }
    appendeeElement.appendChild(newElement);
}

From source file:com.msopentech.odatajclient.engine.data.Serializer.java

private static void xmlLink(final ODataLink link, final Writer writer) {
    try {//w w w .jav a2s . com
        final DocumentBuilder builder = ODataConstants.DOC_BUILDER_FACTORY.newDocumentBuilder();
        final Document doc = builder.newDocument();
        final Element uri = doc.createElementNS(ODataConstants.NS_DATASERVICES, ODataConstants.ELEM_URI);
        uri.appendChild(doc.createTextNode(link.getLink().toASCIIString()));

        dom(uri, writer);
    } catch (Exception e) {
        throw new IllegalArgumentException("While serializing XML link", e);
    }
}

From source file:Main.java

public static Document documentify(ResultSet rs) throws ParserConfigurationException, SQLException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.newDocument();
    Element results = doc.createElement("Results");
    doc.appendChild(results);//w w  w.  j  a va2  s  . co m
    ResultSetMetaData rsmd = rs.getMetaData();
    int colCount = rsmd.getColumnCount();

    while (rs.next()) {
        Element row = doc.createElement("Row");
        results.appendChild(row);
        for (int i = 1; i <= colCount; i++) {
            String columnName = rsmd.getColumnName(i);
            Object value = rs.getObject(i);
            Element node = doc.createElement(columnName);
            node.appendChild(doc.createTextNode(value.toString()));
            row.appendChild(node);
        }
    }
    return doc;
}