Append an xml file to another xml file C# -


this question has answer here:

i have 2 xml files: orderlist.xml

  <listorderitemsresponse xmlns="https://mws.amazonservices.com/orders/2013-09-01">       <listorderitemsresult>         <amazonorderid>102-7574501-6521843</amazonorderid>         <orderitems>           <orderitem>             <asin>b00pboox6c</asin>             <sellersku>oj-j0co-4seh</sellersku>             <orderitemid>03136321944794</orderitemid>             <title>nitric acid 70% , acs, reagent grade, alliance chemical brand, 2.5 liter(7 lbs) bottle</title>             <quantityordered>1</quantityordered>             <quantityshipped>0</quantityshipped>             <itemprice>               <currencycode>usd</currencycode>               <amount>108.00</amount>             </itemprice>             <shippingprice>               <currencycode>usd</currencycode>               <amount>27.00</amount>             </shippingprice>             <giftwrapprice>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </giftwrapprice>             <itemtax>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </itemtax>             <shippingtax>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </shippingtax>             <giftwraptax>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </giftwraptax>             <shippingdiscount>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </shippingdiscount>             <promotiondiscount>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </promotiondiscount>             <promotionids />             <conditionid>new</conditionid>             <conditionsubtypeid>new</conditionsubtypeid>           </orderitem>         </orderitems>       </listorderitemsresult>       <responsemetadata>         <requestid>2b407071-501d-45a2-9baa-2f5ec24f61e7</requestid>       </responsemetadata>     </listorderitemsresponse> 

and orderlist2.xml:

    <listorderitemsresponse xmlns="https://mws.amazonservices.com/orders/2013-09-01">       <listorderitemsresult>         <amazonorderid>112-5324115-6814611</amazonorderid>         <orderitems>           <orderitem>             <asin>b00pgf7u6g</asin>             <sellersku>60-jouw-q8ha</sellersku>             <orderitemid>19976596962514</orderitemid>             <title>nitric acid 70% , acs reagent grade, 2.5 liter(7 lbs) bottle</title>             <quantityordered>1</quantityordered>             <quantityshipped>0</quantityshipped>             <itemprice>               <currencycode>usd</currencycode>               <amount>108.00</amount>             </itemprice>             <shippingprice>               <currencycode>usd</currencycode>               <amount>27.00</amount>             </shippingprice>             <giftwrapprice>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </giftwrapprice>             <itemtax>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </itemtax>             <shippingtax>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </shippingtax>             <giftwraptax>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </giftwraptax>             <shippingdiscount>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </shippingdiscount>             <promotiondiscount>               <currencycode>usd</currencycode>               <amount>0.00</amount>             </promotiondiscount>             <promotionids />             <conditionid>new</conditionid>             <conditionsubtypeid>new</conditionsubtypeid>           </orderitem>         </orderitems>       </listorderitemsresult>       <responsemetadata>         <requestid>e9e67246-c07d-4bf0-825b-929cd37c694f</requestid>       </responsemetadata>     </listorderitemsresponse> 

the combined xml file @ this:

<amazonorderid>112-5324115-6814611</amazonorderid> <orderitems>     <orderitem>         <asin>b00pgf7u6g</asin>         <sellersku>60-jouw-q8ha</sellersku>         <orderitemid>19976596962514</orderitemid>         <title>nitric acid 70% , acs reagent grade, 2.5 liter(7 lbs) bottle</title>         <quantityordered>1</quantityordered>         <quantityshipped>0</quantityshipped>         <itemprice>             <currencycode>usd</currencycode>             <amount>108.00</amount>         </itemprice>         <shippingprice>             <currencycode>usd</currencycode>             <amount>27.00</amount>         </shippingprice>         <giftwrapprice>             <currencycode>usd</currencycode>             <amount>0.00</amount>         </giftwrapprice>         <itemtax>             <currencycode>usd</currencycode>             <amount>0.00</amount>         </itemtax>         <shippingtax>             <currencycode>usd</currencycode>             <amount>0.00</amount>         </shippingtax>         <giftwraptax>             <currencycode>usd</currencycode>             <amount>0.00</amount>         </giftwraptax>         <shippingdiscount>             <currencycode>usd</currencycode>             <amount>0.00</amount>         </shippingdiscount>         <promotiondiscount>             <currencycode>usd</currencycode>             <amount>0.00</amount>         </promotiondiscount>         <promotionids />         <conditionid>new</conditionid>         <conditionsubtypeid>new</conditionsubtypeid>     </orderitem>     <orderitem>         <title>nitric acid 70% , acs reagent grade, 2.5 liter(7 lbs)</title>         <quantityordered>1</quantityordered>         <itemprice>             <amount>108.00</amount>         </itemprice>         <shippingprice>             <amount>27.00</amount>         </shippingprice>     </orderitem> </orderitems>undefined</listorderitemsresult>undefined<responsemetadata> <requestid>e9e67246-c07d-4bf0-825b-929cd37c694f</requestid>undefined</responsemetadata> 

i want append 2nd file 1st file, elements want second file <title>, <quantityordered>, <itemprice>, <amount>, <shippingprice>, <amount>. think think parent element , data should encapsulated within <orderitem> tag. how can this?

if read files , append 1 other, won't valid xml. i'm assuming mean taking of child nodes of root element one, , append them other. means have load both xmldocuments, , import nodes second document first one.

using system.xml;  class program {     static void main(string[] args)      {         xmldocument list1 = new xmldocument();         xmldocument list2 = new xmldocument();         list1.load("orderlist.xml");         list2.load("orderlist2.xml");         foreach (xmlnode childofsecond in list2.documentelement.childnodes)         {             xmlnode childoffirst = list1.importnode(childofsecond, true);             list1.documentelement.appendchild(childoffirst);         }         list1.save("orderlist3.xml");     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -