public xmlGenerator(String articleId, ArrayList<Acell> ma , int numberOfComments) {
			
		level = new int[numberOfComments];
		this.a = ma;
		XmlElement temp;
		
		 try {
				DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
				DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
				Document doc = docBuilder.newDocument();
				
				numberOfMerges = a.size();
				treeQueue = new LinkedList<Element>();
				Element sunOfRoot;

				String root = initMergerMap();
				buildQueue(root);

				//creating the root element
				temp = queue.poll();
				Element rootElement = doc.createElement(XmlElement.ELEMENT_CLUSTER);
				rootElement.setAttribute(XmlElement.ELEMENT_ID,temp.id);
				rootElement.setAttribute(XmlElement.ELEMENT_LEVEL, ""+temp.level);
				rootElement.setAttribute(XmlElement.ELEMENT_MERG_SIM, ""+temp.mergeSim);
				doc.appendChild(rootElement);
				level[temp.level]++;
				pushToqueues(temp);
				
				
				while(numberOfMerges >= 0 )
				{
					//adding the sun on level + 1
					temp = queue.poll();
					sunOfRoot = doc.createElement(XmlElement.ELEMENT_CLUSTER);
					sunOfRoot.setAttribute(XmlElement.ELEMENT_ID,temp.id);
					if(temp.id.equals(rootElement.getAttribute(XmlElement.ELEMENT_ID)))
						sunOfRoot.setAttribute(XmlElement.ELEMENT_MERG_SIM, "1");
					else
						sunOfRoot.setAttribute(XmlElement.ELEMENT_MERG_SIM, ""+temp.mergeSim);
					
					sunOfRoot.setAttribute(XmlElement.ELEMENT_LEVEL, ""+temp.level);
					rootElement.appendChild(sunOfRoot); //adding to XML
					treeQueue.add(sunOfRoot);  //adding to levelOrder queue
					level[temp.level]++;
					pushToqueues(temp); //adding the suns of temp

					//check if the node doesn't have more ( so its can only add itself)
					if(queue.peek().id.equalsIgnoreCase(rootElement.getAttribute(XmlElement.ELEMENT_ID))
							|| (mergeMap.containsKey(temp.id) && !mergeMap.get(temp.id).isEmpty() ))
					{
						//adding the root on level +1 if there any child's
						temp = queue.poll();
						sunOfRoot = doc.createElement(XmlElement.ELEMENT_CLUSTER);
						sunOfRoot.setAttribute(XmlElement.ELEMENT_ID,temp.id);
						sunOfRoot.setAttribute(XmlElement.ELEMENT_LEVEL, ""+temp.level);
						sunOfRoot.setAttribute(XmlElement.ELEMENT_MERG_SIM, ""+temp.mergeSim);
						rootElement.appendChild(sunOfRoot); //adding to XML
						treeQueue.add(sunOfRoot);  //adding to levelOrder queue
						level[temp.level]++;
						pushToqueues(temp); //adding the suns of temp

					}
					
					//TODO: check the last level
					// if the last level already contains all the comments
					if(level[temp.level-1] >= (numberOfComments))
						break;
					rootElement = treeQueue.poll();
				}	
				
				// write the content into xml file
//				TransformerFactory transformerFactory = TransformerFactory.newInstance();
//				Transformer transformer = transformerFactory.newTransformer();
//				DOMSource source = new DOMSource(doc);
//				StreamResult result = new StreamResult(new File("C:\\file.xml"));		 
//				transformer.transform(source, result);
				
				//save the XML representation to the DB
			    DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
			    DatabaseOperations.setXmlRepresentation(articleId,domImplementation.createLSSerializer().writeToString(doc));
			    //save the DOC to the factory
			    new DocFactory().save(new DocDO(articleId,doc));
		
		 }catch (Exception e){ e.printStackTrace();}
	}