java一起添加2个xml文档

时间:2013-11-14 16:59:40

标签: java xml domdocument

我有两个单独的java Document对象:

Doc1:

       <CIS_REQUEST>
           <Request1>
       </CIS_REQUEST>
       <CIS_RESPONSE>
            <RESPONSE1>
            <RESPONSE2>
       </CIS_RESPONSE>

Doc2:

        <CIS_REQUEST>
            <Request1>
        </CIS_REQUEST>

我希望生成的文档看起来像:

 <CIS_REQUEST>
       <Request1>
   </CIS_REQUEST>
   <CIS_RESPONSE>
        <RESPONSE1>
        <RESPONSE2>
   </CIS_RESPONSE>
   <PROCESSING>1</PROCESSING>
   <CIS_PROFILES>
      <CIS_REQUEST>
        <Request1>
      </CIS_REQUEST>
   <CIS_PROFILES>

到目前为止我的代码:

 Document doc2 = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(combinedResponse);
 counter++;
                String counter_str = Integer.toString(counter);
                Element count = doc2.createElement("PROCESSING");
                root.appendChild(count);
                Text counter_text = doc2.createTextNode(counter_str);
                count.appendChild(counter_text);
  Element profileElement = doc2.createElement(profName + "_profiles");
  profileElement.append(doc1)  //I need some replacement for this code.

任何人都可以告诉我如何将一个文档附加到另一个文档,而不是将其插入原始文档中的某个位置?

0 个答案:

没有答案