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.sourceforge.dita4publishers.word2dita.Word2DitaValidationHelper.java

/**
 * @param documentDom//www.ja  v a2s  .c  o m
 * @param commentId
 * @param xpath
 * @throws XPathExpressionException
 */
static void addCommentRefToParaForXPath(Document documentDom, String commentId, String xpath)
        throws XPathExpressionException {
    /**
    <w:r>
     <w:rPr>
       <w:rStyle
         w:val="CommentReference"/>
     </w:rPr>
     <w:commentReference
       w:id="14"/>
    </w:r>
             
     */
    Node node = getWordParaForXPath(documentDom, xpath);

    Element p = (Element) node;
    Element commentRef = documentDom.createElementNS(wNs, "w:r");
    Element elem = (Element) commentRef.appendChild(documentDom.createElementNS(wNs, "w:rPr"));
    elem = (Element) elem.appendChild(documentDom.createElementNS(wNs, "w:rStyle"));
    elem.setAttributeNS(wNs, "w:val", "CommentReference");
    elem = (Element) commentRef.appendChild(documentDom.createElementNS(wNs, "w:commentReference"));
    elem.setAttributeNS(wNs, "w:id", commentId);
    p.appendChild(commentRef);
}

From source file:es.itecban.deployment.security.client.ws.LogonWS.java

private static void addTextNode(Element element, String nodeName, String textValue) {
    // Get the document
    Document doc = element.getOwnerDocument();
    // Write the name
    Node resourceNameNode = doc.createElement(nodeName);
    element.appendChild(resourceNameNode);
    Text resourceNameText = doc.createTextNode(textValue);
    resourceNameNode.appendChild(resourceNameText);
}

From source file:com.moviejukebox.tools.DOMHelper.java

/**
 * Append a child element to a parent element with a single attribute/value pair
 *
 * @param doc/*w ww .jav a  2  s  .  co  m*/
 * @param parentElement
 * @param elementName
 * @param elementValue
 * @param attribName
 * @param attribValue
 */
public static void appendChild(Document doc, Element parentElement, String elementName, String elementValue,
        String attribName, String attribValue) {
    Element child = doc.createElement(elementName);
    Text text = doc.createTextNode(elementValue);
    child.appendChild(text);
    child.setAttribute(attribName, attribValue);
    parentElement.appendChild(child);
}

From source file:com.nridge.core.base.std.XMLUtl.java

public static void makeEscElemStrValue(Document aDocument, Element anElement, String aName, String aValue) {
    Element subElement;

    if ((StringUtils.isNotEmpty(aName)) && (StringUtils.isNotEmpty(aValue))) {
        subElement = aDocument.createElement(aName);
        if (isEscapeNeeded(aValue))
            aValue = escapeElemStrValue(aValue);
        subElement.appendChild(aDocument.createTextNode(aValue));
        anElement.appendChild(subElement);
    }//  ww  w .  ja v  a 2s .c  o m
}

From source file:net.padaf.xmpbox.SaveMetadataHelper.java

/**
 * Prepare XMP Saving Put data necessary to make a well-formed XMP
 * //ww w . j  av  a  2 s.  c o  m
 * @param metadata
 *            metadata concerned by the serialization processing
 * @param intoXPacket
 *            true if Processing instruction must be embedded
 * @return The DOM Document which will represent the serialized metadata
 */
protected static Document prepareSaving(XMPMetadata metadata, boolean intoXPacket) {
    Document newdoc = (Document) metadata.getFuturOwner().cloneNode(true);
    if (intoXPacket) {
        ProcessingInstruction beginXPacket = newdoc.createProcessingInstruction("xpacket",
                "begin=\"" + metadata.getXpacketBegin() + "\" id=\"" + metadata.getXpacketId() + "\"");
        newdoc.appendChild(beginXPacket);
    }

    Element xmpMeta = newdoc.createElementNS("adobe:ns:meta/", "x:xmpmeta");
    xmpMeta.setAttributeNS(XMPSchema.NS_NAMESPACE, "xmlns:x", "adobe:ns:meta/");

    newdoc.appendChild(xmpMeta);
    Element elem = (Element) metadata.getContainerElement().cloneNode(true);
    newdoc.adoptNode(elem);
    xmpMeta.appendChild(elem);

    if (intoXPacket) {
        ProcessingInstruction endXPacket = newdoc.createProcessingInstruction("xpacket",
                metadata.getEndXPacket());
        newdoc.appendChild(endXPacket);
    }
    return newdoc;
}

From source file:com.moviejukebox.tools.DOMHelper.java

/**
 * Add a child element to a parent element with a set of attributes
 *
 * @param doc/*from  w w  w  .j av  a  2  s. c  o  m*/
 * @param parentElement
 * @param elementName
 * @param elementValue
 * @param childAttributes
 */
public static void appendChild(Document doc, Element parentElement, String elementName, String elementValue,
        Map<String, String> childAttributes) {
    Element child = doc.createElement(elementName);
    Text text = doc.createTextNode(elementValue);
    child.appendChild(text);

    if (childAttributes != null && !childAttributes.isEmpty()) {
        for (Map.Entry<String, String> attrib : childAttributes.entrySet()) {
            child.setAttribute(attrib.getKey(), attrib.getValue());
        }
    }

    parentElement.appendChild(child);
}

From source file:Main.java

public static Element getEscalationContactTypeWithText(Document doc, String elementName, String name,
        String title, String street, String city, String state, String zip, String officePhone,
        String mobilePhone, String email, String escalationPhone, String escalationInstructions) {

    Element elem_escalation_contact_type = getContactTypeWithText(doc, elementName, name, title, street, city,
            state, zip, officePhone, mobilePhone, email);

    Element elem_esc_phone = getPhoneTypeWithText(doc, "EscalationPhone", escalationPhone);
    Element elem_esc_instructions = getElementWithText(doc, "EscalationInstructions", escalationInstructions);

    if (escalationPhone != null) {
        elem_escalation_contact_type.appendChild(elem_esc_phone);
    }// ww  w.j ava  2s  . com

    elem_escalation_contact_type.appendChild(elem_esc_instructions);

    return elem_escalation_contact_type;
}

From source file:com.hangum.tadpole.engine.sql.util.export.XMLExporter.java

/**
 * make content//from   w w w . j av a  2s  .  com
 * 
 * @param tableName
 * @param rsDAO
 * @return
 */
public static String makeContent(String tableName, QueryExecuteResultDTO rsDAO, int intLimitCnt)
        throws Exception {
    final StringWriter stWriter = new StringWriter();
    final List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData();

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    final Document doc = builder.newDocument();
    final Element results = doc.createElement(tableName);
    doc.appendChild(results);

    Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName();
    for (int i = 0; i < dataList.size(); i++) {
        Map<Integer, Object> mapColumns = dataList.get(i);
        Element row = doc.createElement("Row");
        results.appendChild(row);

        for (int j = 1; j < mapColumns.size(); j++) {
            String columnName = mapLabelName.get(j);
            String strValue = mapColumns.get(j) == null ? "" : "" + mapColumns.get(j);

            Element node = doc.createElement(columnName);
            node.appendChild(doc.createTextNode(strValue));
            row.appendChild(node);
        }

        if (i == intLimitCnt)
            break;
    }

    DOMSource domSource = new DOMSource(doc);
    TransformerFactory tf = TransformerFactory.newInstance();
    tf.setAttribute("indent-number", 4);

    Transformer transformer = tf.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");

    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//"ISO-8859-1");
    StreamResult sr = new StreamResult(stWriter);
    transformer.transform(domSource, sr);

    return stWriter.toString();
}

From source file:com.hangum.tadpole.engine.sql.util.export.XMLExporter.java

/**
 * make content file//  w  w  w.j a  v  a 2s.  com
 * 
 * @param tableName
 * @param rsDAO
 * @return
 * @throws Exception
 */
public static String makeContentFile(String tableName, QueryExecuteResultDTO rsDAO) throws Exception {
    String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis()
            + PublicTadpoleDefine.DIR_SEPARATOR;
    String strFile = tableName + ".xml";
    String strFullPath = strTmpDir + strFile;

    final StringWriter stWriter = new StringWriter();
    final List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData();

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    final Document doc = builder.newDocument();
    final Element results = doc.createElement(tableName);
    doc.appendChild(results);

    Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName();
    for (int i = 0; i < dataList.size(); i++) {
        Map<Integer, Object> mapColumns = dataList.get(i);
        Element row = doc.createElement("Row");
        results.appendChild(row);

        for (int j = 1; j < mapColumns.size(); j++) {
            String columnName = mapLabelName.get(j);
            String strValue = mapColumns.get(j) == null ? "" : "" + mapColumns.get(j);

            Element node = doc.createElement(columnName);
            node.appendChild(doc.createTextNode(strValue));
            row.appendChild(node);
        }
    }

    DOMSource domSource = new DOMSource(doc);
    TransformerFactory tf = TransformerFactory.newInstance();
    tf.setAttribute("indent-number", 4);

    Transformer transformer = tf.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");

    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//"ISO-8859-1");
    StreamResult sr = new StreamResult(stWriter);
    transformer.transform(domSource, sr);

    FileUtils.writeStringToFile(new File(strFullPath), stWriter.toString(), true);

    return strFullPath;
}

From source file:com.amalto.core.storage.hibernate.DefaultStorageClassLoader.java

private static void addProperty(Document document, Node sessionFactoryElement, String propertyName,
        String propertyValue) {//from   w  ww  .j a  v a2 s .c o m
    Element property = document.createElement("property"); //$NON-NLS-1$
    Attr name = document.createAttribute("name"); //$NON-NLS-1$
    name.setValue(propertyName);
    property.getAttributes().setNamedItem(name);
    property.appendChild(document.createTextNode(propertyValue));
    sessionFactoryElement.appendChild(property);
}