private Document addElements(Document doc, Element currentElement,
			GenericTreeNode<LayoutParserTreeElement> Node)
			throws TransformerException {
		Element child;

		// Gaseste copiii nodului curent
		List<GenericTreeNode<LayoutParserTreeElement>> children = Node
				.getChildren();
		Iterator<GenericTreeNode<LayoutParserTreeElement>> it = children
				.iterator();

		// Itereaza prin fiecare copil
		while (it.hasNext()) {
			GenericTreeNode<LayoutParserTreeElement> childNode = it.next();
			LayoutParserTreeElement childElement = childNode.getData();

			if (childElement.text.isEmpty() == false
					&& childElement.toString().compareTo("String") == 0) {
				// Este frunza
				child = doc.createElement(childElement.toString());
				child.appendChild(doc.createTextNode(childElement.text
						.toString()));

			} else if (childElement.text.isEmpty() == true
					&& childElement.toString().compareTo("String") == 0) {

				child = doc.createElement(childElement.toString());
			} else {
				// Creaza elementul
				child = doc.createElement(childElement.toString());

				// Adauga atributele
				if (childElement.shouldOutputCoords()) {
					// Bottom
					Attr bottom = doc.createAttribute("bottom");
					bottom.setValue(Integer.toString(childElement.bottom));
					child.setAttributeNode(bottom);

					// Top
					Attr top = doc.createAttribute("top");
					top.setValue(Integer.toString(childElement.top));
					child.setAttributeNode(top);

					// Right
					Attr right = doc.createAttribute("right");
					right.setValue(Integer.toString(childElement.right));
					child.setAttributeNode(right);

					// Left
					Attr left = doc.createAttribute("left");
					left.setValue(Integer.toString(childElement.left));
					child.setAttributeNode(left);
				}

				// Is type point
				if (childElement.x != null) {
					Attr x = doc.createAttribute("x");
					x.setValue(childElement.x);
					child.setAttributeNode(x);
					Attr y = doc.createAttribute("y");
					y.setValue(childElement.y);
					child.setAttributeNode(y);
				}

				// Are atribut hasPage
				if (childElement.hasPage == true) {
					Attr hasPage = doc.createAttribute("type");
					hasPage.setValue("page_number");
					child.setAttributeNode(hasPage);
				}

				// Adauga elementul la arbore
				currentElement.appendChild(child);
			}

			currentElement.appendChild(child);

			// Merge mai jos in arbore
			addElements(doc, child, childNode);
		}

		return doc;
	}