Index: trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorOutputWriter.java
===================================================================
--- trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorOutputWriter.java	(revision 1268)
+++ trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorOutputWriter.java	(revision 1315)
@@ -204,8 +204,4 @@
         }
         
-        if (guiStructure != null) {
-            dumpGuiStructure(guiStructure);
-        }
-        
         for (HtmlEvent event : events) {
             dumpEvent(event);
@@ -226,47 +222,4 @@
     /**
      * <p>
-     * dumps the GUI structure provided by the parameter into the log file. Calls itself
-     * recursively to traverse the GUI structure.
-     * </p>
-     *
-     * @param guiStructure the GUI structure to be logged
-     */
-    private void dumpGuiStructure(HtmlGUIElement guiStructure) {
-        if (!loggedGUIElements.contains(guiStructure)) {
-            outputWriter.print("<component id=\"");
-            outputWriter.print(guiStructure.getId());
-            outputWriter.println("\">");
-        
-            if (guiStructure instanceof HtmlServer) {
-                dumpParam("host", ((HtmlServer) guiStructure).getName());
-                dumpParam("port", ((HtmlServer) guiStructure).getPort());
-            }
-            else if (guiStructure instanceof HtmlDocument) {
-                dumpParam("path", ((HtmlDocument) guiStructure).getPath());
-                dumpParam("query", ((HtmlDocument) guiStructure).getQuery());
-                dumpParam("title", ((HtmlDocument) guiStructure).getTitle());
-            }
-            else if (guiStructure instanceof HtmlPageElement) {
-                dumpParam("tagname", ((HtmlPageElement) guiStructure).getTagName());
-                dumpParam("htmlid", ((HtmlPageElement) guiStructure).getHtmlId());
-                dumpParam("index", ((HtmlPageElement) guiStructure).getIndex());
-            }
-            
-            dumpParam("parent", guiStructure.getParentId());
-        
-            outputWriter.println("</component>");
-        
-            loggedGUIElements.add(guiStructure);
-        }
-        
-        if (guiStructure.getChildren() != null) {
-            for (HtmlGUIElement child : guiStructure.getChildren()) {
-                dumpGuiStructure(child);
-            }
-        }
-    }
-
-    /**
-     * <p>
      * formats a received event and writes it to the log file. One event results in one line
      * in the log file containing all infos of the event.
@@ -276,4 +229,8 @@
      */
     private void dumpEvent(HtmlEvent event) {
+        if (event.getTarget() != null) {
+            ensureGuiElementDumped(event.getTarget());
+        }
+        
         outputWriter.print("<event type=\"");
         outputWriter.print(event.getEventType());
@@ -304,4 +261,50 @@
         
         outputWriter.println("</event>");
+    }
+
+    /**
+     * <p>
+     * dumps a GUI element starting with its parent GUI elements into the log file. Calls itself
+     * recursively to traverse for dumping the parents first.
+     * </p>
+     *
+     * @param guiStructure the GUI structure to be logged
+     */
+    private void ensureGuiElementDumped(HtmlGUIElement guiElement) {
+        if (!loggedGUIElements.contains(guiElement)) {
+            
+            HtmlGUIElement parent = guiElement.getParent();
+            String parentId = null;
+            
+            if (parent != null) {
+                ensureGuiElementDumped(parent);
+                parentId = parent.getId();
+            }
+            
+            outputWriter.print("<component id=\"");
+            outputWriter.print(guiElement.getId());
+            outputWriter.println("\">");
+        
+            if (guiElement instanceof HtmlServer) {
+                dumpParam("host", ((HtmlServer) guiElement).getName());
+                dumpParam("port", ((HtmlServer) guiElement).getPort());
+            }
+            else if (guiElement instanceof HtmlDocument) {
+                dumpParam("path", ((HtmlDocument) guiElement).getPath());
+                dumpParam("query", ((HtmlDocument) guiElement).getQuery());
+                dumpParam("title", ((HtmlDocument) guiElement).getTitle());
+            }
+            else if (guiElement instanceof HtmlPageElement) {
+                dumpParam("tagname", ((HtmlPageElement) guiElement).getTagName());
+                dumpParam("htmlid", ((HtmlPageElement) guiElement).getHtmlId());
+                dumpParam("index", ((HtmlPageElement) guiElement).getIndex());
+            }
+            
+            dumpParam("parent", parentId);
+        
+            outputWriter.println("</component>");
+        
+            loggedGUIElements.add(guiElement);
+        }
     }
 
