[Previous slide] [Next slide] Moving to XML

Let's see that again (ii): the event element

The event element is a simple wrapper round a context element:

/** an XML element representing a single event. This uses
 *  ContextElement which knows how to construct a DOM element node by
 *  taking values out of a context, so all we need to do is tell it
 *  which value names to treat as attributes and which as children */
class EventElement extends ContextElement
{
    /** The name of this particular element type */
    protected static String name = "event";

    public EventElement( DocumentImpl doc, Context source)
    {
    super( doc, name, source);
    }

    /** return a String array of the names of my properties to output
     *  as attributes */
    protected String[] getAttrNames()
    {
    String[] attrNames = 
    { "event", "type", "location", "starttime", "endtime", "actor"};

    return attrNames;
    }

    /** return a String array of the names of my properties to output
     *  as children */
    protected String[] getChildNames()
    {
    String[] childNames = { "description"};

    return childNames;
    }
}

 


An older version of this course is available here