Here you can find the source of addElementWithText(Document document, Element parentElement, String newElementName, String textString)
Parameter | Description |
---|---|
document | the document into which the element is added. |
parentElement | The parent element of the element-to-be-added. |
newElementName | name of new element (tag-name). |
textString | the text to be written inside the newly created element. |
public static Element addElementWithText(Document document, Element parentElement, String newElementName, String textString)
//package com.java2s; /**/*from www . j a va 2s . c o m*/ * Copyright 2015 Yahoo Inc.<br> * Licensed under the terms of the MIT license. Please see LICENSE file at the root of this project for terms. * <p/> * * @author yuvalp@yahoo-inc.com * */ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; public class Main { /** * Creates a new element, with the given text inside that element. * * @param document the document into which the element is added. * @param parentElement The parent element of the element-to-be-added. * @param newElementName name of new element (tag-name). * @param textString the text to be written inside the newly created element. * @return The new element. */ public static Element addElementWithText(Document document, Element parentElement, String newElementName, String textString) { Element newElement = document.createElement(newElementName); Text text = document.createTextNode(textString); newElement.appendChild(text); parentElement.appendChild(newElement); return newElement; } }