/*
 *	Modulname:	Testbench
 *	Autor:		Eyer Leander
 *	Datum:		08.05.2006
 *
 *	(c) Copyright 2005
 */
package survey;

import java.io.IOException;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

/**
 * A way to visualize an already answered survey
 */
public class Test {

    public static void main(String [] args) throws Exception {
	String surveyFileName = args[0];

	FileInputStream input = new FileInputStream(surveyFileName);

	//prepare parser
	DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
	dbFactory.setIgnoringComments(true);
	dbFactory.setNamespaceAware(false);
	dbFactory.setValidating(false);
	DocumentBuilder builder = dbFactory.newDocumentBuilder();

	//parse the xml file
	org.w3c.dom.Document xmlDocument = builder.parse(input);
	input.close();

	//extract the survey
	Element surveyConfigNode = xmlDocument.getDocumentElement();

	Element answersElement = (Element)surveyConfigNode.getElementsByTagName("Answers").item(0);
	//read all type templates
	NodeList answerList = answersElement.getElementsByTagName("QA");
        for (int i = 0; i < answerList.getLength(); i++) {
	    Element answerElement = (Element) answerList.item(i);

	    String questionId = answerElement.getAttribute("id");
	    
	    String answer = answerElement.getElementsByTagName("Answer").item(0).getTextContent();

	    System.out.println(questionId + "\t" + answer);
	}

    }
}

