Index: /trunk/autoquest-androidmonitor/src/de/ugoe/cs/autoquest/androidmonitor/Androidmonitor.java
===================================================================
--- /trunk/autoquest-androidmonitor/src/de/ugoe/cs/autoquest/androidmonitor/Androidmonitor.java	(revision 1727)
+++ /trunk/autoquest-androidmonitor/src/de/ugoe/cs/autoquest/androidmonitor/Androidmonitor.java	(revision 1728)
@@ -23,12 +23,7 @@
 
 	String activityName; // name of the activity Class that starts a Tracker
-	
-	//Handle XML
-	private XmlSerializer xmlSerializer = Xml.newSerializer(); // handle XML tracking
-	private StringWriter stringWriter = new StringWriter(); // used with XmlSerializer
-	
-	//Log file
+
+	// Log file
 	private AndroidmonitorLogFile logFile;
-	
 
 	/**
@@ -49,10 +44,9 @@
 	public void startMonitor(Activity activity) {
 		activityName = activity.getClass().getSimpleName();
-		
-		logFile = new AndroidmonitorLogFile(getAppLable(activity), activity.getFilesDir());		
+
+		logFile = new AndroidmonitorLogFile(getAppLable(activity),
+				activity.getFilesDir());
 
 		addLogListenerToView(getRootView(activity));
-
-		
 
 		// tbd
@@ -102,34 +96,4 @@
 
 	/**
-	 * generates the path of an view element
-	 * 
-	 * @param view
-	 * @return path to the element
-	 */
-	private String getViewPath(View view) {
-		return getViewPath(view, null);
-	}
-
-	/**
-	 * generates the path of an view element
-	 * 
-	 * @param view
-	 * @param path
-	 * @return path to the element
-	 */
-	private String getViewPath(View view, String path) {
-		if (path == null) {
-			path = "";
-		} else {
-			path = view.getClass().getSimpleName() + "/" + path;
-		}
-		if (view.getParent() != null && (view.getParent() instanceof ViewGroup)) {
-			return getViewPath((View) view.getParent(), path);
-		} else {
-			return path;
-		}
-	}
-
-	/**
 	 * replace the listener of each view with a composite listener which
 	 * collects several listeners for one view.
@@ -139,4 +103,5 @@
 	public void addLogListenerToView(View view) {
 		// traverse all views of the activity
+		logFile.addComponent(view, activityName);
 		if (view instanceof ViewGroup) {
 			ViewGroup group = (ViewGroup) view;
@@ -161,45 +126,13 @@
 				public void onClick(View v) {
 
+					logFile.addEvent(v);
+
 					// track information ...
-					Log.d("MyLog",
-							"activity:" + activityName + " id:" + v.getId()
-									+ " element:"
-									+ v.getClass().getSimpleName() + " path:"
-									+ getViewPath(v) + " x:" + v.getX() + " y:"
-									+ v.getY() + " time:"
-									+ System.currentTimeMillis());
-					String viewId = "" + v.getId();
-					String x = "" + v.getX();
-					String y = "" + v.getY();
-
-					XmlSerializer serializer = Xml.newSerializer(); // handle
-																	// XML
-																	// tracking
-					StringWriter writer = new StringWriter();
-
-					try {
-						serializer.setOutput(writer);
-						serializer.startTag("", "event");
-						serializer.attribute("", "id", viewId);
-						serializer.startTag("", "param");
-						serializer.attribute("", "value", x);
-						serializer.attribute("", "name", "X");
-						serializer.endTag("", "param");
-						serializer.startTag("", "param");
-						serializer.attribute("", "value", y);
-						serializer.attribute("", "name", "Y");
-						serializer.endTag("", "param");
-						serializer.startTag("", "param");
-						serializer.attribute("", "value", v.getClass()
-								.getSimpleName());
-						serializer.attribute("", "name", v.getClass()
-								.getSimpleName());
-						serializer.endTag("", "param");
-						serializer.endTag("", "event");
-						serializer.endDocument();
-						Log.d("xml", writer.toString());
-					} catch (Exception e) {
-						throw new RuntimeException(e);
-					}
+					// Log.d("MyLog",
+					// "activity:" + activityName + " id:" + v.getId()
+					// + " element:"
+					// + v.getClass().getSimpleName() + " x:" + v.getX() + " y:"
+					// + v.getY() + " time:"
+					// + System.currentTimeMillis());
 
 				}
@@ -279,21 +212,25 @@
 		return retrievedListener;
 	}
-	
+
 	/**
 	 * get application name as defined in Package Name
-	 * @param pContext package context; could also be an activity
+	 * 
+	 * @param pContext
+	 *            package context; could also be an activity
 	 * @return app name
 	 */
 	public String getAppLable(Context pContext) {
-		//source (2014-09-04): http://stackoverflow.com/questions/11229219/android-get-application-name-not-package-name 
-	    PackageManager lPackageManager = pContext.getPackageManager();
-	    ApplicationInfo lApplicationInfo = null;
-	    try {
-	        lApplicationInfo = lPackageManager.getApplicationInfo(pContext.getApplicationInfo().packageName, 0);
-	    } catch (final NameNotFoundException e) {
-	    }
-	    return (String) (lApplicationInfo != null ? lPackageManager.getApplicationLabel(lApplicationInfo) : "Unknown");
-	}
-	
+		// source (2014-09-04):
+		// http://stackoverflow.com/questions/11229219/android-get-application-name-not-package-name
+		PackageManager lPackageManager = pContext.getPackageManager();
+		ApplicationInfo lApplicationInfo = null;
+		try {
+			lApplicationInfo = lPackageManager.getApplicationInfo(
+					pContext.getApplicationInfo().packageName, 0);
+		} catch (final NameNotFoundException e) {
+		}
+		return (String) (lApplicationInfo != null ? lPackageManager
+				.getApplicationLabel(lApplicationInfo) : "Unknown");
+	}
 
 }
Index: /trunk/autoquest-androidmonitor/src/de/ugoe/cs/autoquest/androidmonitor/AndroidmonitorLogFile.java
===================================================================
--- /trunk/autoquest-androidmonitor/src/de/ugoe/cs/autoquest/androidmonitor/AndroidmonitorLogFile.java	(revision 1727)
+++ /trunk/autoquest-androidmonitor/src/de/ugoe/cs/autoquest/androidmonitor/AndroidmonitorLogFile.java	(revision 1728)
@@ -2,5 +2,7 @@
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.StringWriter;
 
@@ -9,8 +11,14 @@
 import android.util.Log;
 import android.util.Xml;
+import android.view.View;
+import android.view.ViewGroup;
 
 public class AndroidmonitorLogFile {
 
+	// TODO rename getDeviceInformation() and getAppInformation() to set ... use
+	// writeToFile for both
+
 	private String name;
+	private File file;
 
 	public AndroidmonitorLogFile(String appName, File dir) {
@@ -19,5 +27,5 @@
 		try {
 			// prove if file exists
-			File file = new File(dir, this.name);
+			this.file = new File(dir, this.name);
 			/*
 			 * if file does not exists write device and app information to a new
@@ -25,5 +33,5 @@
 			 * file.
 			 */
-			if (true) { //!file.exists() 
+			if (true) { // !this.file.exists()
 				/*
 				 * create log file. Using method openFileOutput() does not work
@@ -36,13 +44,21 @@
 				 * another app directory as the own one.
 				 */
-				String string = getDeviceInformation() + getAppInformation();
+
+				// TODO split document head information from
+				// getDeviceInformation.
+
+				String string = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><session>"
+						+ getDeviceInformation() + getAppInformation();
 				try {
-					FileOutputStream outputStream = new FileOutputStream(file);
+					FileOutputStream outputStream = new FileOutputStream(
+							this.file);
 					outputStream.write(string.getBytes());
 					outputStream.close();
 				} catch (Exception e) {
-					Log.e("file", "outputstream: " + e.getMessage());
+					Log.e("this.file", "outputstream: " + e.getMessage());
 				}
 
+			} else {
+				// tbd add activity information
 			}
 		} catch (Exception e) {
@@ -62,16 +78,23 @@
 	}
 
+	// should be set
 	private String getAppInformation() {
-		// app Name ...
+		// TODO create app information in the same manner as coded in
+		// getDeviceInformation
 		return "";
 	}
 
+	/**
+	 * Query device information. XML format.
+	 * 
+	 * @return
+	 */
+	// should be set
 	private String getDeviceInformation() {
 		String deviceInformation = "";
-		XmlSerializer serializer = Xml.newSerializer(); 
+		XmlSerializer serializer = Xml.newSerializer();
 		StringWriter writer = new StringWriter();
 		try {
 			serializer.setOutput(writer);
-			serializer.startDocument("UTF-8", true);
 			serializer.startTag("", "device");
 			serializer.startTag("", "param");
@@ -96,13 +119,13 @@
 			serializer.endTag("", "param");
 
-			// tbd get resolution ...
+			// TODO get resolution ...
 
 			serializer.endTag("", "device");
 			serializer.endDocument();
-			
+
 			deviceInformation = writer.toString();
 
-		} catch (Exception e) {
-			Log.e("xml", e.getMessage()); 
+		} catch (IOException e) {
+			Log.e("xml", e.getMessage());
 		}
 
@@ -110,10 +133,156 @@
 	}
 
-	public void addComponent() {
-		// add component to file
-	}
-
-	public void addEvent() {
-		// add event to file
+	public void addComponent(View view, String activityName) {
+		XmlSerializer serializer = Xml.newSerializer();
+		StringWriter writer = new StringWriter();
+		// create HEX string
+
+		try {
+			serializer.setOutput(writer);
+			serializer.startTag("", "component");
+			// TODO use hex string instead of integer number
+			serializer.attribute("", "hash", "" + view.hashCode());
+
+			serializer.startTag("", "param");
+			serializer.attribute("", "name", "id");
+			serializer.attribute("", "value", "" + view.getId());
+			serializer.endTag("", "param");
+
+			serializer.startTag("", "param");
+			serializer.attribute("", "name", "path");
+			serializer.attribute("", "value", activityName + "/"
+					+ getViewPath(view));
+			serializer.endTag("", "param");
+
+			serializer.startTag("", "param");
+			serializer.attribute("", "name", "class");
+			serializer.attribute("", "value", view.getClass().getName());
+			serializer.endTag("", "param");
+
+			serializer.startTag("", "param");
+			serializer.attribute("", "name", "parent");
+			// serializer.attribute("", "value", "" +
+			// view.getParent().hashCode());
+			serializer.endTag("", "param");
+
+			serializer.endTag("", "component");
+			serializer.endDocument();
+
+			writeToFile(writer.toString());
+
+		} catch (IllegalArgumentException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			Log.e("file", "outputstream: " + e.getMessage());
+		} catch (IllegalStateException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			Log.e("file", "outputstream: " + e.getMessage());
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			Log.e("file", "outputstream: " + e.getMessage());
+		}
+
+	}
+
+	public void addEvent(View view) {
+
+		String x = "" + view.getX();
+		String y = "" + view.getY();
+
+		XmlSerializer serializer = Xml.newSerializer();
+		StringWriter writer = new StringWriter();
+
+		try {
+			serializer.setOutput(writer);
+
+			serializer.startTag("", "event");
+			serializer.attribute("", "type", view.getClass().getSimpleName());
+
+			serializer.startTag("", "param");
+			serializer.attribute("", "value", x);
+			serializer.attribute("", "name", "X");
+			serializer.endTag("", "param");
+
+			serializer.startTag("", "param");
+			serializer.attribute("", "value", y);
+			serializer.attribute("", "name", "Y");
+			serializer.endTag("", "param");
+
+			serializer.startTag("", "param");
+			serializer.attribute("", "value", "" + view.hashCode());
+			serializer.attribute("", "name", "source");
+			serializer.endTag("", "param");
+
+			serializer.startTag("", "param");
+			serializer.attribute("", "value", "" + System.currentTimeMillis());
+			serializer.attribute("", "name", "timestamp");
+			serializer.endTag("", "param");
+
+			serializer.endTag("", "event");
+			serializer.endDocument();
+
+			writeToFile(writer.toString());
+		} catch (IllegalArgumentException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			Log.e("file", "outputstream: " + e.getMessage());
+		} catch (IllegalStateException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			Log.e("file", "outputstream: " + e.getMessage());
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			Log.e("file", "outputstream: " + e.getMessage());
+		}
+	}
+
+	private void writeToFile(String data) {
+
+		FileOutputStream outputStream;
+		try {
+			outputStream = new FileOutputStream(file, true);
+			outputStream.write(data.getBytes());
+			outputStream.close();
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+			Log.e("file", "outputstream: " + e.getMessage());
+		} catch (IOException e) {
+			e.printStackTrace();
+			Log.e("file", "outputstream: " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * generates the path of an view element
+	 * 
+	 * @param view
+	 * @return path to the element
+	 */
+	private String getViewPath(View view) {
+		return getViewPath(view, null);
+	}
+
+	/**
+	 * generates the path of an view element
+	 * 
+	 * @param view
+	 * @param path
+	 * @return path to the element
+	 */
+	private String getViewPath(View view, String path) {
+		if (path == null) {
+			path = "";
+		} else {
+			path = view.getClass().getSimpleName() + "/" + path;
+		}
+		if (view.getParent() != null && (view.getParent() instanceof ViewGroup)) {
+			return getViewPath((View) view.getParent(), path);
+		} else {
+			return path;
+		}
 	}
 
