Index: trunk/src/scriptbuilder/structures/SimulationScript.java
===================================================================
--- trunk/src/scriptbuilder/structures/SimulationScript.java	(revision 30)
+++ trunk/src/scriptbuilder/structures/SimulationScript.java	(revision 38)
@@ -19,4 +19,5 @@
 import scriptbuilder.structures.ScriptIncident.IncidentFocusedEvent;
 import scriptbuilder.structures.ScriptIncident.SliceChangedEvent;
+import scriptbuilder.structures.units.Unit;
 
 /**
@@ -56,4 +57,9 @@
     public List<ScriptIncident> incidents;
 
+    /**
+     * The units which participate in Unit events.
+     */
+    public List<Unit> units;
+
     //Somewhere in the code, something assumes that the list of incidents
     //contains exactly 10 items. Until I can find and un-break that, this will do.
@@ -80,17 +86,7 @@
         sh = new MyScriptHandler(this);
         incidents = new ArrayList<ScriptIncident>();
+        units = new ArrayList<Unit>();
         numberOfIncidents = 0;
 
-        // Create the media event
-        /*incidents.add(new ScriptIncident(incidentColors[0], 100, "Media",
-         "An incident for the media in CAD.", 10800, this));
-         numberOfIncidents++;
-         // Create the "other" event
-         incidents.add(new ScriptIncident(incidentColors[9], 999, "Other",
-         "An incident for small-scale events, false events, "
-         + "and noise.  All events added to this incident will "
-         + "receive a randomly generated incident number.",
-         10800, this));
-         numberOfIncidents++;*/
         //Backfill with null incidents
         for (int i = numberOfIncidents; i < INCIDENT_FILL_COUNT; i++)
@@ -98,63 +94,4 @@
             incidents.add(null);
         }
-        /*
-         Add some demo events
-         incidents.add(new ScriptIncident(incidentColors[1], 174, "Blueberry Truck",
-         "Blueberry truck crashed on the freeway.", 8800, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[2], 175, "Construction Crash",
-         "Crash at construction site on Red Road.", 6800, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[3], 176, "Car Freeway Flip",
-         "Car flipped across the lane divider on the freeway.", 7200, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[4], 177, "Two Lane Crash",
-         "Crash taking two lanes on Tree Road.", 4200, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[5], 178, "Stalled Truck",
-         "Truck stalled on the freeway.", 2800, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[6], 179, "Tomato Truck Spill",
-         "Tomato trucked spilt tomatos all over the freeway.", 3200, this));
-         incidents.add(new ScriptIncident(incidentColors[7], 180, "Crash at Intersection",
-         "Crash at the intersection of Tree Road and Red Road.", 4300, this));
-         incidents.add(new ScriptIncident(incidentColors[8], 181, "Bomb Threat",
-         "Bomb threat and Road X.", 6000, this));
-         incidents.add(null);
-         incidents.add(null);
-         incidents.add(null);
-         Random rng = new Random();
-         ScriptEventType[] eventTypes = ScriptEventType.values();
-         if (numberOfIncidents > 0)
-         {
-         for (int i = 0; i < 300; i++)
-         {
-         int n = rng.nextInt();
-         int s = rng.nextInt();
-         int e = rng.nextInt();
-         if (n < 0)
-         {
-         n *= -1;
-         }
-         if (s < 0)
-         {
-         s *= -1;
-         }
-         if (e < 0)
-         {
-         e *= -1;
-         }
-         incidents.get(n % numberOfIncidents).slices.get(s % (incidents.get(n % numberOfIncidents).slices.size())).addEvent(new ScriptEvent(eventTypes[e % eventTypes.length]));
-         }  
-         incidents.get(1).setOffset(200);
-         incidents.get(2).setOffset(3400);
-         incidents.get(3).setOffset(1400);
-         incidents.get(4).setOffset(4400);
-         incidents.get(5).setOffset(1400);
-         incidents.get(6).setOffset(7600);
-         incidents.get(7).setOffset(2400);
-         incidents.get(8).setOffset(4800); 
-         }
-         */
     }
 
@@ -207,5 +144,5 @@
 
             Vector<ScriptIncident> inc = sh.getIncidents();
-
+            units = sh.getUnits();
             for (ScriptIncident sci : inc)
             {
@@ -246,8 +183,18 @@
     public String toXML()
     {
+        ArrayList<TimeSlice> slices = allSlices();
         String output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
-        output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">";
-        ArrayList<TimeSlice> slices = allSlices();
+        output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">\n";
         output += openTag(ELEMENT.TMC_SCRIPT.tag + " title=\"" + this.title + "\"");
+
+        if (units.size() > 0)
+        {
+            output += openTag(ELEMENT.SCRIPT_DATA.tag);
+            for (Unit unit : units)
+            {
+                output += unit.toXML();
+            }
+            output += closeTag(ELEMENT.SCRIPT_DATA.tag);
+        }
         for (TimeSlice slice : slices)
         {
@@ -261,5 +208,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
@@ -291,5 +238,5 @@
             for (ScriptIncident inc : incidents)
             {
-                
+
                 if (inc != null && inc.slices.get(i) != null)
                 {
Index: trunk/src/scriptbuilder/structures/TimeSlice.java
===================================================================
--- trunk/src/scriptbuilder/structures/TimeSlice.java	(revision 37)
+++ trunk/src/scriptbuilder/structures/TimeSlice.java	(revision 38)
@@ -260,5 +260,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/ScriptIncident.java
===================================================================
--- trunk/src/scriptbuilder/structures/ScriptIncident.java	(revision 34)
+++ trunk/src/scriptbuilder/structures/ScriptIncident.java	(revision 38)
@@ -254,5 +254,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/units/Unit.java
===================================================================
--- trunk/src/scriptbuilder/structures/units/Unit.java	(revision 1)
+++ trunk/src/scriptbuilder/structures/units/Unit.java	(revision 38)
@@ -5,4 +5,7 @@
  */
 package scriptbuilder.structures.units;
+
+import scriptbuilder.structures.ELEMENT;
+import scriptbuilder.structures.I_XML_Writable;
 
 /**
@@ -13,46 +16,210 @@
  * @author Bryan McGuffin
  */
-public class Unit
+public class Unit implements I_XML_Writable
 {
 
-    public String UnitNum = "";
-
-    public String ID = "";
-
-    public String Status = "";
-
-    public String Master_Inc_Num = "";
-
-    public String Primary = "";
-
-    public String OOS = "";
-
-    public String Type = "";
-
-    public String Curr_Loc = "";
-
-    public String Destination = "";
-
-    public String Misc_Info = "";
-
-    public String Stack = "";
-
-    public String Area = "";
-
-    public String Officer = "";
-
-    public String Badge_Num = "";
-
-    public String Timer = "";
-
-    public String Office = "";
-
-    public String P = "";
-
-    public String Agy = "";
-
-    public String Alias = "";
-
-    public String Unit_Status = "";
-
+    public String UnitNum;
+
+    public String ID;
+
+    public String Status;
+
+    public String Master_Inc_Num;
+
+    public String Primary;
+
+    public String OOS;
+
+    public String Type;
+
+    public String Curr_Loc;
+
+    public String Destination;
+
+    public String Misc_Info;
+
+    public String Stack;
+
+    public String Area;
+
+    public String Officer;
+
+    public String Badge_Num;
+
+    public String Timer;
+
+    public String Office;
+
+    public String P;
+
+    public String Agy;
+
+    public String Alias;
+
+    public String Unit_Status;
+
+    public Unit()
+    {
+        UnitNum = "";
+
+        ID = "";
+
+        Status = "";
+
+        Master_Inc_Num = "";
+
+        Primary = "";
+
+        OOS = "";
+
+        Type = "";
+
+        Curr_Loc = "";
+
+        Destination = "";
+
+        Misc_Info = "";
+
+        Stack = "";
+
+        Area = "";
+
+        Officer = "";
+
+        Badge_Num = "";
+
+        Timer = "";
+
+        Office = "";
+
+        P = "";
+
+        Agy = "";
+
+        Alias = "";
+
+        Unit_Status = "";
+    }
+
+    @Override
+    public String toXML()
+    {
+        String output = openTag(ELEMENT.NEW_UNIT.tag + " UnitNum=\"" + UnitNum + "\"");
+
+        if (!ID.equals(""))
+        {
+            output += openTag(ELEMENT.ID.tag) + ID + closeTag(ELEMENT.ID.tag);
+        }
+
+        if (!Status.equals(""))
+        {
+            output += openTag(ELEMENT.STATUS.tag) + Status + closeTag(ELEMENT.STATUS.tag);
+        }
+
+        if (!Master_Inc_Num.equals(""))
+        {
+            output += openTag(ELEMENT.MASTER_INC_NUM.tag) + Master_Inc_Num + closeTag(ELEMENT.MASTER_INC_NUM.tag);
+        }
+
+        if (!Primary.equals(""))
+        {
+            output += openTag(ELEMENT.PRIMARY.tag) + Primary + closeTag(ELEMENT.PRIMARY.tag);
+        }
+
+        if (!OOS.equals(""))
+        {
+            output += openTag(ELEMENT.OOS.tag) + OOS + closeTag(ELEMENT.OOS.tag);
+        }
+
+        if (!Type.equals(""))
+        {
+            output += openTag(ELEMENT.TYPE.tag) + Type + closeTag(ELEMENT.TYPE.tag);
+        }
+
+        if (!Curr_Loc.equals(""))
+        {
+            output += openTag(ELEMENT.CURR_LOC.tag) + Curr_Loc + closeTag(ELEMENT.CURR_LOC.tag);
+        }
+
+        if (!Destination.equals(""))
+        {
+            output += openTag(ELEMENT.DESTINATION.tag) + Destination + closeTag(ELEMENT.DESTINATION.tag);
+        }
+
+        if (!Misc_Info.equals(""))
+        {
+            output += openTag(ELEMENT.MISC_INFO.tag) + Misc_Info + closeTag(ELEMENT.MISC_INFO.tag);
+        }
+
+        if (!Stack.equals(""))
+        {
+            output += openTag(ELEMENT.STACK.tag) + Stack + closeTag(ELEMENT.STACK.tag);
+        }
+
+        if (!Area.equals(""))
+        {
+            output += openTag(ELEMENT.AREA.tag) + Area + closeTag(ELEMENT.AREA.tag);
+        }
+
+        if (!Badge_Num.equals(""))
+        {
+            output += openTag(ELEMENT.BADGE_NUM.tag) + Badge_Num + closeTag(ELEMENT.BADGE_NUM.tag);
+        }
+
+        if (!Officer.equals(""))
+        {
+            output += openTag(ELEMENT.OFFICER.tag) + Officer + closeTag(ELEMENT.OFFICER.tag);
+        }
+
+        if (!Office.equals(""))
+        {
+            output += openTag(ELEMENT.OFFICE.tag) + Office + closeTag(ELEMENT.OFFICE.tag);
+        }
+
+        if (!Timer.equals(""))
+        {
+            output += openTag(ELEMENT.TIMER.tag) + Timer + closeTag(ELEMENT.TIMER.tag);
+        }
+
+        if (!P.equals(""))
+        {
+            output += openTag(ELEMENT.P.tag) + P + closeTag(ELEMENT.P.tag);
+        }
+
+        if (!Agy.equals(""))
+        {
+            output += openTag(ELEMENT.AGY.tag) + Agy + closeTag(ELEMENT.AGY.tag);
+        }
+
+        if (!Alias.equals(""))
+        {
+            output += openTag(ELEMENT.ALIAS.tag) + Alias + closeTag(ELEMENT.ALIAS.tag);
+        }
+
+        if (!Unit_Status.equals(""))
+        {
+            output += openTag(ELEMENT.UNIT_STATUS.tag) + Unit_Status + closeTag(ELEMENT.UNIT_STATUS.tag);
+        }
+
+        output += closeTag(ELEMENT.NEW_UNIT.tag);
+        return output;
+    }
+
+    @Override
+    public String openTag(String s)
+    {
+        return "<" + s + ">";
+    }
+
+    @Override
+    public String closeTag(String s)
+    {
+        return "</" + s + ">\n";
+    }
+
+    @Override
+    public String emptyTag(String s)
+    {
+        return "<" + s + "/>\n";
+    }
 }
Index: trunk/src/scriptbuilder/structures/events/UnitEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/UnitEvent.java	(revision 35)
+++ trunk/src/scriptbuilder/structures/events/UnitEvent.java	(revision 38)
@@ -35,5 +35,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/CADEvaluationEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/CADEvaluationEvent.java	(revision 37)
+++ trunk/src/scriptbuilder/structures/events/CADEvaluationEvent.java	(revision 38)
@@ -68,5 +68,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/TMTRadioEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/TMTRadioEvent.java	(revision 36)
+++ trunk/src/scriptbuilder/structures/events/TMTRadioEvent.java	(revision 38)
@@ -38,5 +38,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/TelephoneEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/TelephoneEvent.java	(revision 35)
+++ trunk/src/scriptbuilder/structures/events/TelephoneEvent.java	(revision 38)
@@ -56,5 +56,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/RadioEvaluationEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/RadioEvaluationEvent.java	(revision 37)
+++ trunk/src/scriptbuilder/structures/events/RadioEvaluationEvent.java	(revision 38)
@@ -69,5 +69,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/ActivityLogEvaluationEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/ActivityLogEvaluationEvent.java	(revision 37)
+++ trunk/src/scriptbuilder/structures/events/ActivityLogEvaluationEvent.java	(revision 38)
@@ -68,5 +68,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/CADEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/CADEvent.java	(revision 35)
+++ trunk/src/scriptbuilder/structures/events/CADEvent.java	(revision 38)
@@ -40,5 +40,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/CHPRadioEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/CHPRadioEvent.java	(revision 35)
+++ trunk/src/scriptbuilder/structures/events/CHPRadioEvent.java	(revision 38)
@@ -54,5 +54,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/FacilitatorEvaluationEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/FacilitatorEvaluationEvent.java	(revision 37)
+++ trunk/src/scriptbuilder/structures/events/FacilitatorEvaluationEvent.java	(revision 38)
@@ -68,5 +68,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/WitnessEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/WitnessEvent.java	(revision 36)
+++ trunk/src/scriptbuilder/structures/events/WitnessEvent.java	(revision 38)
@@ -43,5 +43,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/ATMSEvaluationEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/ATMSEvaluationEvent.java	(revision 37)
+++ trunk/src/scriptbuilder/structures/events/ATMSEvaluationEvent.java	(revision 38)
@@ -68,5 +68,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/CCTVEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/CCTVEvent.java	(revision 36)
+++ trunk/src/scriptbuilder/structures/events/CCTVEvent.java	(revision 38)
@@ -39,5 +39,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/ParamicsEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/ParamicsEvent.java	(revision 35)
+++ trunk/src/scriptbuilder/structures/events/ParamicsEvent.java	(revision 38)
@@ -36,5 +36,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/AudioEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/AudioEvent.java	(revision 35)
+++ trunk/src/scriptbuilder/structures/events/AudioEvent.java	(revision 38)
@@ -37,5 +37,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/MaintenanceRadioEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/MaintenanceRadioEvent.java	(revision 28)
+++ trunk/src/scriptbuilder/structures/events/MaintenanceRadioEvent.java	(revision 38)
@@ -40,5 +40,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/TowEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/TowEvent.java	(revision 36)
+++ trunk/src/scriptbuilder/structures/events/TowEvent.java	(revision 38)
@@ -35,5 +35,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/events/CMSEvaluationEvent.java
===================================================================
--- trunk/src/scriptbuilder/structures/events/CMSEvaluationEvent.java	(revision 36)
+++ trunk/src/scriptbuilder/structures/events/CMSEvaluationEvent.java	(revision 38)
@@ -87,5 +87,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
Index: trunk/src/scriptbuilder/structures/MyScriptHandler.java
===================================================================
--- trunk/src/scriptbuilder/structures/MyScriptHandler.java	(revision 37)
+++ trunk/src/scriptbuilder/structures/MyScriptHandler.java	(revision 38)
@@ -244,4 +244,5 @@
         incidentMap = new TreeMap<Integer, ScriptIncident>();
         eventMap = new TreeMap<ELEMENT, I_ScriptEvent>();
+        unitMap = new TreeMap<String, Unit>();
         pcData = new TreeMap<ELEMENT, String>();
         docPosition = new Stack<ELEMENT>();
@@ -257,4 +258,14 @@
         return new Vector<ScriptIncident>(incidentMap.values());
     }
+    
+    /**
+     * Get the list of units that have been parsed from the script file.
+     *
+     * @returns Vector of Unit objects.
+     */
+    public Vector<Unit> getUnits()
+    {
+        return new Vector<Unit>(unitMap.values());
+    }
 
     /**
@@ -265,8 +276,5 @@
     {
         //System.out.println("STUB: Start the document");
-        for (ELEMENT e : ELEMENT.values())
-        {
-            pcData.put(e, null);
-        }
+        
     }
 
@@ -601,5 +609,4 @@
     public void endElement(String uri, String localName, String qName)
     {
-
         currentElement = docPosition.pop();
         I_ScriptEvent newEvent = null;
@@ -791,5 +798,5 @@
             }
 
-            else if (qName.equals(ELEMENT.INCIDENT.tag))
+            else if (currentElement == ELEMENT.INCIDENT)
             {
                 currentIncName = parsedValue.toString();
@@ -805,5 +812,5 @@
 
             }
-            else if (qName.equals(ELEMENT.NEW_UNIT))
+            else if (currentElement == ELEMENT.NEW_UNIT)
             {
                 if (unitMap.get(NewUnitNum) == null)
@@ -879,4 +886,5 @@
                         unit.Timer = pcData.remove(ELEMENT.TIMER);
                     }
+                    unitMap.put(NewUnitNum, unit);
                 }
             }
