title: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it
body: <p>I have created a method which takes three paremeters of types Node, Document and String respectively. The method creates an Element type and appends it to the node.</p>
  
  <pre><code>public Node populateProcessNodeRecursively (Node node, Document doc, String name){
      if (name.equals("WFD.Stencils.WF_START")){
          Element startEventNode = createNewNodeElement (doc, "bpmn2:startEvent");
          startEventNode.setAttribute("id", arrayOfNodesIds.get(ind));
          node.appendChild(startEventNode);
      }
      return node;
  }
  </code></pre>
  
  <p>where the implementation of <code>createNewNodeElement</code> method is:</p>
  
  <pre><code>public static Element createNewNodeElement (Document doc, String tagName){
      Element theNodeElement = doc.createElement(tagName);
      return theNodeElement;
  }
  </code></pre>
  
  <p>But I get the following exception :</p>
  
  <blockquote>
    <p>Exception in thread "main" <code>org.w3c.dom.DOMException</code>: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.</p>
  </blockquote>
  
  <p>exactly when i try to append the newly created element to the node. </p>
  
  <p>I have solved the same problem when I tried to append to my document an element from another
   existing document using importNode but I don't know how to fix this problem because i am in the same document, i am not retrieving nodes from another doc</p>