I am trying to append one XML within another XML but unable to do so. Can someone please help me with this.
I'll try to explain what I am trying to do.

From the main method of my class, a method called createCompleteXML() will be called. Before this method is called a variable with the name skelotonXML (StringBuffer) would already be set. The value of this (StringBuffer) skeletonXML would be something like

Java Code:
<feedback>
    <fb_info>
        <fb_id>27006971</fb_id>
    </fb_info>
    <fb_responses>
        <fb_response_approval>
            <res_id/>
        </ fb_response_approval >
        <fb_input_approve>
            <res_id/>
        </ fb_input_approve >
    </fb_responses>
</feedback>
This method called createCompleteXML() would iterate over this skeletonXML (which I have now converted to DOM from StringBuffer) and call relevant classes and methods to create a complete XML. While iterating over this skeletonXML whenever <fb_info>, <fb_response_approval> or <fb_input_approve> element is encountered a class is called. Class to be called for <fb_info> is CreateFeedbackXML, class to be called for <fb_response_approval> is CreateResponseApprovalXML and class to be called for <fb_input_approve> is CreateApproverXML.
All these classes implement the following interface
Java Code:
public interface IXMLCreator {
	public StringBuffer getXMLChunck(String id, IDfSession session);
}
These implementation classes will return an XML in the form of
Java Code:
 <fb123>
    <feedback_id><![CDATA[27006971]]></feedback_id>
    <operation_division/>
    <fb_brand><![CDATA[ert]]></fb_brand>
    <fb_url/>
</fb123>
This XML needs to be added to the original skelotonXML inside the same element, encountering on which the class was instantiated.
Example,while iterating over skeletonXML, <fb_info> element is encountered. Now getXMLChunck() method of CreateFeedbackXML will be called. This method will return an XML in the form of
Java Code:
<fb123>
    <feedback_id><![CDATA[27006971]]></feedback_id>
    <operation_division/>
    <fb_brand><![CDATA[ert]]></fb_brand>
    <fb_url/>
</fb123>
This XML I need to append to the original skeleton XML. So that the skeletonXML becomes
Java Code:
<feedback>
    <fb_info>
            <fb123>
                <feedback_id><![CDATA[27006971]]></feedback_id>
                <operation_division/>
               <fb_brand><![CDATA[ert]]></fb_brand>
               <fb_url/>
            </fb123>
    </fb_info>
    <fb_responses>
        <fb_response_approval>
            <res_id/>
        </ fb_response_approval >
        <fb_input_approve>
            <res_id/>
        </ fb_input_approve >
    </fb_responses>
</feedback>
Still the code will continue to iterate over the skeleton XML and it will now encounter, <fb_response_approval> element. Now it will call getXMLChunck() method of CreateResponseApprovalXML. This method will return an XML in the form
Java Code:
<fb456>
    <feedback_id><![CDATA[2700633222]]></feedback_id>
    <fb_brand><![CDATA[eeee]]></fb_brand>
    <fb_url/>
</fb456>
This XML needs to be appended at the appropriate place in the skeleton XML so that the skeleton XML becomes
Java Code:
<feedback>
    <fb_info>
             <fb123>
                <feedback_id><![CDATA[27006971]]></feedback_id>
                <operation_division/>
                <fb_brand><![CDATA[ert]]></fb_brand>
                <fb_url/>
             </fb123>
    </fb_info>
    <fb_responses>
        <fb_response_approval>
           <fb456>
                <feedback_id><![CDATA[2700633222]]></feedback_id>
                <fb_brand><![CDATA[eeee]]></fb_brand>
                <fb_url/>
           </fb456>
        </ fb_response_approval >
        <fb_input_approve>
            <res_id/>
        </ fb_input_approve >
    </fb_responses>
</feedback>
This will go on till all the children of fb_responses have been encountered.
This code which I am using for traversing the skeleton XML and appending XML from Helper classes to it is as follows
Java Code:
public void createCompleteXML() {
	 try {
	   // create a new DocumentBuilder object
	   DocumentBuilder builder = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
	   Document document = builder.parse(new org.xml.sax.InputSource(new StringReader(skeletonXml.toString())));
	   
	   Element root = document.getDocumentElement();
       System.out.println("The root element is " + root.getNodeName() + ".\n");
       
       NodeList feedbackNodeList = document.getElementsByTagName("fb_info");
       for(int i=0; i<feedbackNodeList.getLength(); i++) {
    	   Node childOfFeedback = feedbackNodeList.item(i);
    	   if (childOfFeedback.getNodeType() == childOfFeedback.ELEMENT_NODE) {
	    	   String strChildOfFeedback = childOfFeedback.getNodeName();
	    	   System.out.println(childOfFeedback.getNodeName()+"  :  "+childOfFeedback.getNodeValue());
	    	   
	    	   if(strChildOfFeedback.equalsIgnoreCase("fb_info")) {
	    		   IXMLCreator cfxml = new CreateFeedbackXML();
            	   StringBuffer xmlChunck = cfxml.getXMLChunck(feedback_id, session);
                   System.out.println("fb id from XML is :  "+childOfFeedback.getChildNodes().item(0).getTextContent());                   
            	   System.out.println("xml chunck:  "+xmlChunck);            	 
            	   Document docXmlChunck = builder.parse(new org.xml.sax.InputSource(new StringReader(xmlChunck.toString())));
            	   Node nodeXmlChunck = docXmlChunck.getDocumentElement();
            	   Node importedNode = document.importNode(nodeXmlChunck, true);
            	   childOfFeedback = childOfFeedback.appendChild(importedNode);
            	   NodeList testchildren = childOfFeedback.getChildNodes(); 
            	   for(int k=0; k<testchildren.getLength(); k++) {
            		   System.out.println("Yest    -"+testchildren.item(k).getNodeName()+"   ---   "+testchildren.item(k).getTextContent());
            	   }
            	   
            	   System.out.println("child of fb -----------++++++ : "+childOfFeedback.toString());
	    	   } 
    	   }
       }
       
       NodeList responsesNodeList = document.getElementsByTagName("fb_responses");
       Node responsesNode = responsesNodeList.item(0);
     
       for (Node child = responsesNode.getFirstChild();child != null;child = child.getNextSibling()) {
           if (child.getNodeType() == child.ELEMENT_NODE) {
                System.out.println("-----"+child.getNodeName());
                String strChildOfResponses = child.getNodeName();
                
                if(strChildOfResponses.equalsIgnoreCase("fb_input_approve")) {
 	    		   IXMLCreator cfxml = new CreateApproverXML();
 	    		   String response_id=child.getChildNodes().item(0).getTextContent();
 	    		   System.out.println("Response id from Approver XML is :  "+response_id);
 	    		   StringBuffer xmlChunck = cfxml.getXMLChunck(response_id, session);
                                       
             	   System.out.println("approver xml chunck:  "+xmlChunck);
        //     	  Document docXmlChunck = builder.parse(new org.xml.sax.InputSource(new StringReader(xmlChunck.toString())));
           	      /*Node nodeXmlChunck = docXmlChunck.getDocumentElement();
           	      childOf = document.importNode(nodeXmlChunck, true);
           	      NodeList testchildren = childOfFeedback.getChildNodes(); 
           	      for(int k=0; k<testchildren.getLength(); k++) {
           		     System.out.println("Yest    -"+testchildren.item(k).getNodeName()+"   ---   "+testchildren.item(k).getTextContent());
           	   }*/
           	
 	    	   } 
           }
       }      
      
     
      
   
       
	 } catch (org.xml.sax.SAXException e) {
		  e.printStackTrace(); // or throw a Exception
	  } catch (java.io.IOException e) {
		  e.printStackTrace(); // or throw a Exception
	  } catch (javax.xml.parsers.ParserConfigurationException e) {
	      e.printStackTrace(); // or throw a Exception
	 }
	}
After appending, when I try to print the dom object using
for(int k=0; k<testchildren.getLength(); k++) {
System.out.println("Yest -"+testchildren.item(k).getNodeName()+" --- "+testchildren.item(k).getTextContent());
}
I see only the xml which was returned by helper class and not the complete xml.
Can some expert please help me with this