import java.lang.reflect.*;

/**
 * Uses reflection to write an XML
 * representation of simple objects
 *
 * @author  Computer Science Deprtment, James Madison University
 * @version 1.0
 */
public class XMLWriter
{
    /**
     * Write the object
     *
     * @param obj   The Object
     */
    public void write(Object obj) throws Exception
    {
	Class         obj_Class;
	Field[]       obj_Fields;
	int           i;


	obj_Class = obj.getClass();
	System.out.println(" < "+obj_Class.getName()+" > ");

	obj_Fields = obj_Class.getDeclaredFields();
	for (i=0; i < obj_Fields.length; i++) 
        {
	    System.out.print(" < "+obj_Fields[i].getName()+" > ");
	    System.out.print(obj_Fields[i].get(obj));
	    System.out.print(" </ "+obj_Fields[i].getName()+" > \n");
	}
	System.out.println(" </ "+obj_Class.getName()+" > ");
    }

}
