Java Reference
In-Depth Information
An Xbean chain starts with an Xbean that either reads an existing document from a stream or crea tes
one from some data source. Listing 17-4 illustrates a simple Xbean that creates an XML document from
the system clock.
Listing 17-4: SystemTime bean
package JavaDatabaseBible.ch17.Xbeans;
import java.io.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.Xbeans.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.xerces.dom.DocumentImpl;
/**
* Create a w3c.dom.Document containg system time and date.
*/
public class SystemTimeBean extends JavaDatabaseBible.ch17.Xbeans.XBean{
protected String textFileName = "";
public SystemTimeBean() {
}
public void processDocument() throws XbeansException{
GregorianCalendar calendar = new GregorianCalendar();
try{
Document doc = new DocumentImpl();
Element root = (Element) doc.createElement("SYSTEMDATE");
doc.appendChild (root);
Element year = (Element) doc.createElement("YEAR");
root.appendChild(year);
year.appendChild(doc.createTextNode(""+calendar.get(Calendar.YEAR)));
Element month = (Element) doc.createElement("MONTH");
root.appendChild(month);
int mon = calendar.get(Calendar.MONTH)+1;
month.appendChild(doc.createTextNode(String.valueOf(mon)));
Element day = (Element) doc.createElement("DAY");
root.appendChild(day);
Search WWH ::




Custom Search