Java tutorial
//package com.java2s; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import org.w3c.dom.Element; public class Main { /** * Creates an attribute with content in the form of a date/time */ public static void setDateTimeAttribute(Element element, String name, DateTime value) { DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZ"); setAttribute(element, name, dtf.print(value)); } /** * Creates an attribute with a given text content */ public static void setAttribute(Element element, String name, String value) { element.setAttribute(name, value); } /** * Creates an attribute with content in the form of an integer */ public static void setAttribute(Element element, String name, int value) { setAttribute(element, name, Integer.toString(value)); } /** * Creates an attribute with content in the form of a Boolean */ public static void setAttribute(Element element, String name, boolean value) { setAttribute(element, name, value ? "S" : "N"); } /** * Creates an attribute with content in the form of a double */ public static void setAttribute(Element element, String name, double value) { setAttribute(element, name, Double.toString(value)); } /** * Creates an attribute with content in the form of a date */ public static void setAttribute(Element element, String name, DateTime value) { DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd"); setAttribute(element, name, dtf.print(value)); } }