private Element iterativeCreateElement (Element elem, HashMap<String, String> hmap, Document wDoc) {
        String tagName = elem.getNodeName();
        NodeList children = elem.getChildNodes();
        Element writeElem = wDoc.createElement(tagName);

        for (int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            short nodeType = node.getNodeType();


            if (nodeType == Node.ELEMENT_NODE) {
                //in order to avoid empty TEXT_NODE, the following code is different from that in iterativeParseElement
                if (node.getChildNodes().getLength() == 1 && node.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) {
                    Element writeSubElem = wDoc.createElement(node.getNodeName());
                    writeElem.appendChild(writeSubElem);
                    // System.out.println(node.getNodeName());
                    writeSubElem.appendChild(wDoc.createTextNode(hmap.get(node.getNodeName())));
                }
                else {
                    Element writeSubElem = iterativeCreateElement((Element)node, hmap, wDoc);
                    writeElem.appendChild(writeSubElem);
                }
            }
        }
        return writeElem;
    }