Home » xmlbeans-2.5.0-src » org.apache.xmlbeans.samples » datetime » [javadoc | source]
public class: DateTime [javadoc | source]
The sample illustrates how you can work with XML Schema types date, dateTime, time, duration, gDay. It parses the XML Document, prints first occurence of value, creates a new element and saves it in a new XML Document. This sample illustrates how you can convert XMLBean types to Java types (java.util.Date, java.util.Calendar). It uses the schema defined in datetime.xsd.
Method from org.apache.xmlbeans.samples.datetime.DateTime Summary:
createDocument,   main,   parseXml,   printInstance,   validateXml
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.xmlbeans.samples.datetime.DateTime Detail:
 public  void createDocument(DatetimeDocument doc,
    String file) 
    This method creates an new element and attaches to the existing XML Instance, and saves the new Instance to a file(args[1]).
 public static  void main(String[] args) 
    Receives an XML Instance and prints the element values, Also creates a new XML Instance.
 public DatetimeDocument parseXml(String file) 
    Creates a File from the XML path provided in main arguments, then parses the file's contents into a type generated from schema.
 public  void printInstance(DatetimeDocument doc) 
    This method prints first occurence of value. It also prints converted values from XMLBean types to Java types (java.util.Date, java.util.Calendar) and org.apache.xmlbeans.GDate.
 public boolean validateXml(XmlObject xml) 

    Validates the XML, printing error messages when the XML is invalid. Note that this method will properly validate any instance of a compiled schema type because all of these types extend XmlObject.

    Note that in actual practice, you'll probably want to use an assertion when validating if you want to ensure that your code doesn't pass along invalid XML. This sample prints the generated XML whether or not it's valid so that you can see the result in both cases.