如何拼接兩結構相同的XML文檔

來源:互聯網
上載者:User
在工作中遇到這樣的問題:
在主表單中使用者可以添加5項產品
多餘的產品必須開啟另外一張表單以附件形式添加
最後儲存的時候將主表單和附件表格單的資料一起提交,以下是我的實現方式:
  var xmlAccessories = createDomDocument();
  var xmlInsertDoc = createDomDocument();

                           xmlAccessories.loadXML(“<DETAILS>
                                                                         <TABLE>
                                                                                <Res>6</Res>
                                                                                <Type>6</Type>
                                                                                <Magnitude>6</Magnitude>
                                                                                <Budget>6</Budget>
                                                                                <Price>36</Price>
                                                                                <Date>2009-09-06</Date>
                                                                         </TABLE>
                                                                         <TABLE>
                                                                                <Res>7</Res>
                                                                                <Type>7</Type>
                                                                                <Magnitude>7</Magnitude>
                                                                                <Budget>7</Budget>
                                                                                <Price>49</Price>
                                                                                <Date>2009-09-07</Date>
                                                                         </TABLE>
                                                                  </DETAILS>”);
  xmlInsertDoc.loadXML( "<DETAILS>
                                     <TABLE>
                                            <Res>1</Res>
                                            <Type>1</Type>
                                            <Magnitude>1</Magnitude>
                                            <Budget>1</Budget>
                                            <Price>1</Price>
                                            <Date>2009-09-01</Date>
                                     </TABLE>      
                                     <TABLE>
                                           <Res>2</Res>
                                            <Type>2</Type>
                                            <Magnitude>2</Magnitude>
                                            <Budget>2</Budget>
                                            <Price>4</Price>
                                            <Date>2009-09-02</Date>
                                     </TABLE>
                                     <TABLE>
                                            <Res>3</Res>
                                            <Type>3</Type>
                                            <Magnitude>3</Magnitude>
                                            <Budget>3</Budget>
                                            <Price>9</Price>
                                            <Date>2009-09-03</Date>
                                     </TABLE>
                                     <TABLE>
                                            <Res>4</Res>
                                            <Type>4</Type>
                                            <Magnitude>4</Magnitude>
                                            <Budget>4</Budget>
                                            <Price>16</Price>
                                            <Date>2009-09-04</Date>
                                     </TABLE>
                                     <TABLE>
                                            <Res>5</Res>
                                            <Type>5</Type>
                                            <Magnitude>5</Magnitude>
                                            <Budget>5</Budget>
                                            <Price>25</Price>
                                            <Date>2009-09-05</Date>
                               </TABLE>
                  </DETAILS>");
  var nodeAccess =  xmlAccessories.documentElement;
  var nodeDetails = xmlInsertDoc.documentElement.selectSingleNode("DETAILS");
  //var nodeTable = nodeAccess.firstChild;
  //while(nodeTable!=null)
  //{
  // nodeDetails.appendChild(nodeTable.cloneNode(true));
  // nodeTable=nodeTable.nextSibling;
  //}
  
  for(var i=nodeAccess.childNodes.length-1;i>=0;i--)
  {
   var nodeTable = nodeAccess.childNodes[i];
   nodeDetails.appendChild(nodeTable);
  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.