<commit_before>package org.javarosa.model.xform;

import java.io.DataOutputStream;
import java.util.Enumeration;
import java.util.Hashtable;

import org.javarosa.core.model.IAnswerDataSerializer;
import org.javarosa.core.model.IFormDataModel;
import org.javarosa.core.model.instance.DataModelTree;
import org.javarosa.core.model.instance.QuestionDataElement;
import org.javarosa.core.model.instance.QuestionDataGroup;
import org.javarosa.core.model.instance.TreeElement;
import org.javarosa.core.model.utils.IDataModelSerializingVisitor;
import org.javarosa.core.model.utils.ITreeVisitor;
import org.javarosa.xform.util.JavaRosaXformsParser;
import org.kxml2.kdom.Document;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;

/**
 * A visitor class which walks a DataModelTree and constructs an XML document
 * containing its instance.
 * 
 * The XML node elements are constructed in a depth-first manner, consistent with
 * standard XML document parsing.
 * 
 * @author <NAME>
 *
 */
public class XFormSerializingVisitor implements IDataModelSerializingVisitor, ITreeVisitor {

	/** The XML document containing the instance that is to be returned */
	Document theXmlDoc;
	
	/** A hashtable linking TreeElements to the xml element that they should add themselves to */
	Hashtable parentList;
	
	/** The serializer to be used in constructing XML for AnswerData elements */
	IAnswerDataSerializer serializer;
	
	/*
	 * (non-Javadoc)
	 * @see org.javarosa.core.model.utils.ITreeVisitor#visit(org.javarosa.core.model.DataModelTree)<commit_msg>[r608] [branches/dev] Added a new application specific Exception. Fixed some hanging references. Reorganized some namespaces.<commit_after>package org.javarosa.model.xform;

import java.io.DataOutputStream;
import java.util.Enumeration;
import java.util.Hashtable;

import org.javarosa.core.model.IAnswerDataSerializer;
import org.javarosa.core.model.IFormDataModel;
import org.javarosa.core.model.instance.DataModelTree;
import org.javarosa.core.model.instance.QuestionDataElement;
import org.javarosa.core.model.instance.QuestionDataGroup;
import org.javarosa.core.model.instance.TreeElement;
import org.javarosa.core.model.instance.utils.ITreeVisitor;
import org.javarosa.core.model.utils.IDataModelSerializingVisitor;
import org.javarosa.xform.util.JavaRosaXformsParser;
import org.kxml2.kdom.Document;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;

/**
 * A visitor class which walks a DataModelTree and constructs an XML document
 * containing its instance.
 * 
 * The XML node elements are constructed in a depth-first manner, consistent with
 * standard XML document parsing.
 * 
 * @author <NAME>
 *
 */
public class XFormSerializingVisitor implements IDataModelSerializingVisitor, ITreeVisitor {

	/** The XML document containing the instance that is to be returned */
	Document theXmlDoc;
	
	/** A hashtable linking TreeElements to the xml element that they should add themselves to */
	Hashtable parentList;
	
	/** The serializer to be used in constructing XML for AnswerData elements */
	IAnswerDataSerializer serializer;
	
	/*
	 * (non-Javadoc)
	 * @see org.javarosa.core.model.utils.ITreeVisitor#visit(org.javarosa.core.model.DataModelTree)
{'fraction_non_alphanumeric': 0.08926905132192846, 'fraction_numerical': 0.0027993779160186624, 'mean_word_length': 5.2084942084942085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4232828', 'n_tokens_mistral': 994, 'n_tokens_neox': 948, 'n_words': 245}