Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { /** * Append application specific tags into xml signature document * @param document * @return */ public static Document addUserInfoToSignature(Document document) { Element signature = document.getDocumentElement(); // initially it has no root-element, ... so we create it: Element root = document.createElement("digital-signature"); Element subjInfo = document.createElement("subject-information"); subjInfo.appendChild(document.createElement("subject")); subjInfo.appendChild(document.createElement("date")); subjInfo.appendChild(document.createElement("time")); subjInfo.appendChild(document.createElement("timestamp")); root.appendChild(subjInfo); root.appendChild(signature); // we can add an element to a document only once, // the following calls will raise exceptions: document.appendChild(root); document.setXmlStandalone(true); return document; } }