Java tutorial
//package com.java2s; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { /** * * @param doc * @param elem * @param name * @param value * @param comment */ public static void createChildTextWithComment(Document doc, Element elem, String name, String value, String comment) { Element child = doc.createElement(name); child.appendChild(doc.createTextNode(value == null ? "" : value)); Comment c = doc.createComment(comment); elem.appendChild(c); elem.appendChild(child); } public static void createComment(Document doc, Element elem, String comment) { Comment c = doc.createComment(comment); elem.appendChild(c); } }