public static void fillEndorsementElement(Document doc, X509Info x509info,
			String defaultEmail) {

		String emailAddress = defaultEmail;

		NodeList nl = doc.getElementsByTagNameNS(SLREQ_NS_URI, "endorsement");
		if (nl.getLength() != 1) {
			throw new MetadataException(
					"document must contain exactly 1 slreq:endorsement element");
		}

		if (x509info.email != null) {
			emailAddress = x509info.email;
		}

		if (emailAddress == null || "".equals(emailAddress)) {
			throw new MetadataException(
					"cannot generate slreq:endorsement; email address not in cert or not provided");
		}

		if (!isValidEmailAddress(emailAddress)) {
			throw new MetadataException("invalid email address: "
					+ emailAddress);
		}

		Node endorsement = nl.item(0);

		if (!endorsement.hasChildNodes()) {

			endorsement.appendChild(createTimestampElement(doc));

			Element email = createSlreqElement(doc, "email");
			email.setTextContent(emailAddress);

			Element subject = createSlreqElement(doc, "subject");
			subject.setTextContent(x509info.subject);

			Element issuer = createSlreqElement(doc, "issuer");
			issuer.setTextContent(x509info.issuer);

			Element endorser = createSlreqElement(doc, "endorser");
			Attr attr = doc.createAttributeNS(RDF_NS_URI, "parseType");
			attr.setTextContent("Resource");
			endorser.setAttributeNodeNS(attr);
			endorser.appendChild(email);
			endorser.appendChild(subject);
			endorser.appendChild(issuer);

			endorsement.appendChild(endorser);
		}

		doc.normalizeDocument();
	}