Here you can find the source of createElementWithText(Element parent, String name, String value)
Parameter | Description |
---|---|
parent | a parameter |
name | a parameter |
value | a parameter |
public static Element createElementWithText(Element parent, String name, String value)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import org.w3c.dom.Document; public class Main { /**// w w w. j a va2 s.c om * helper method, creates a subelement with text embedded. does not format * the result. primarily to be used in cases like * <code><goals><goal>xxx</goal></goals></code> * * @param parent * @param name * @param value * @return */ public static Element createElementWithText(Element parent, String name, String value) { Document doc = parent.getOwnerDocument(); Element newElement = doc.createElement(name); parent.appendChild(newElement); newElement.appendChild(doc.createTextNode(value)); return newElement; } /** * helper method, creates a subelement, does not format result. * * @param parent * the parent element * @param name * the name of the new element * @return the created element */ public static Element createElement(Element parent, String name) { Document doc = parent.getOwnerDocument(); Element newElement = doc.createElement(name); parent.appendChild(newElement); return newElement; } }