title: C# - XML - Compression
body: <p>I have a situation where I am generating a XML file to be submitted to a webservice, sometimes due to the amount of data it exceeds 30mb or 50mb. </p>
  
  <p>I need to compress the file, using c#, .net framework 4.0, rather one of the nodes which has most of the data.. I have no idea how i am going to do it .. is it possible if someone can give me a example of how I can get this done please. </p>
  
  <p>the xml file looks like this </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;HeaderTalk xmlns="http://www.w3schools.com/xml"&gt;
  &lt;EnvelopeVersion&gt;2.0&lt;/EnvelopeVersion&gt;
  &lt;Header&gt;
  &lt;MessageDetails&gt;
    &lt;Class&gt;CHAR-CLM&lt;/Class&gt;      
  &lt;/MessageDetails&gt;
  &lt;SenderDetails&gt;
    &lt;IDAuthentication&gt;
      &lt;SenderID&gt;aaaaaa&lt;/SenderID&gt;
      &lt;Authentication&gt;
        &lt;Method&gt;MD5&lt;/Method&gt;
        &lt;Role&gt;principal&lt;/Role&gt;
        &lt;Value&gt;a3MweCsv60kkAgzEpXeCqQ==&lt;/Value&gt;
      &lt;/Authentication&gt;
    &lt;/IDAuthentication&gt;
    &lt;EmailAddress&gt;Someone@somewhere.com&lt;/EmailAddress&gt;
  &lt;/SenderDetails&gt;
  &lt;/Header&gt;
  &lt;TalkDetails&gt;
    &lt;ChannelRouting&gt;
     &lt;Channel&gt;
       &lt;URI&gt;1953&lt;/URI&gt;
       &lt;Product&gt;My product&lt;/Product&gt;
       &lt;Version&gt;2.0&lt;/Version&gt;
      &lt;/Channel&gt;
  &lt;/ChannelRouting&gt;
  &lt;/TalkDetails&gt;
  &lt;Body&gt;
     &lt;envelope xmlns="http://www.w3schools.com/xml/"&gt;       
       &lt;PeriodEnd&gt;2013-08-13&lt;/PeriodEnd&gt;
       &lt;IRmark Type="generic"&gt;zZrxvJ7JmMNaOyrMs9ZOaRuihkg=&lt;/IRmark&gt;
       &lt;Sender&gt;Individual&lt;/Sender&gt;
       &lt;Report&gt;
         &lt;AuthOfficial&gt;
            &lt;OffName&gt;
              &lt;Fore&gt;B&lt;/Fore&gt;
              &lt;Sur&gt;M&lt;/Sur&gt;
            &lt;/OffName&gt;
            &lt;Phone&gt;0123412345&lt;/Phone&gt;
          &lt;/AuthOfficial&gt;
      &lt;DefaultCurrency&gt;GBP&lt;/DefaultCurrency&gt;
      &lt;Claim&gt;
        &lt;OrgName&gt;B&lt;/OrgName&gt;
        &lt;ref&gt;AB12345&lt;/ref&gt;
        &lt;Repayment&gt;
          &lt;Account&gt;
            &lt;Donor&gt;
              &lt;Fore&gt;Barry&lt;/Fore&gt;
             &lt;/Donor&gt;
              &lt;Total&gt;7.00&lt;/Total&gt;              
          &lt;/Account&gt;           
          &lt;Account&gt;
            &lt;Donor&gt;
              &lt;Fore&gt;Anthony&lt;/Fore&gt;               
            &lt;/Donor&gt;             
            &lt;Total&gt;20.00&lt;/Total&gt;
          &lt;/Account&gt;                  
        &lt;/Repayment&gt;
        &lt;/Claim&gt;
        &lt;/Report&gt;
     &lt;/envelope&gt;
   &lt;/Body&gt;
  &lt;/HeaderTalk&gt;
  </code></pre>
  
  <p>The <strong>CLAIM node</strong> is what I want to Compress , as it can be Millions of records that get included in the XML. </p>
  
  <p>I am a novice in coding, it has taken a long time for me to get this XML generated, and been searching to find a way to compress the node but I just cant get it to work.. 
  the Result needs to be exactly same till the  DefaultCurrency node.. 
  and then </p>
  
  <pre><code> &lt;/AuthOfficial&gt;
   &lt;DefaultCurrency&gt;GBP&lt;/DefaultCurrency&gt;
   &lt;CompressedPart Type="zip"&gt;UEsDBBQAAAAIAFt690K1&lt;/CompressedPart&gt;
   &lt;/Report&gt;
   &lt;/envelope&gt;
   &lt;/Body&gt;
   &lt;/HeaderTalk&gt;
  </code></pre>
  
  <p>or </p>
  
  <pre><code> &lt;/AuthOfficial&gt;
   &lt;DefaultCurrency&gt;GBP&lt;/DefaultCurrency&gt;
   &lt;CompressedPart Type="gzip"&gt;UEsDBBQAAAAIAFt690K1&lt;/CompressedPart&gt;
   &lt;/Report&gt;
   &lt;/envelope&gt;
   &lt;/Body&gt;
   &lt;/HeaderTalk&gt;
  </code></pre>
  
  <p>Thank you everyone in advance please.  Or if someone can suggest where I can look and get some idea, on what I want to do.  </p>
  
  <p>to create the file , I am simple iterating through a Dataset and Writing the nodes using XmlElements and setting innertexts to my values .. </p>
  
  <p>The Code I have used to write is .. 
   //claim</p>
  
  <pre><code>XmlElement GovtSenderClaim = xmldoc.CreateElement("Claim");
  XmlElement GovtSenderOrgname = xmldoc.CreateElement("OrgName");
  GovtSenderOrgname.InnerText = Charity_name;
  GovtSenderClaim.AppendChild(GovtSenderOrgname);
  
   XmlElement GovtSenderHMRCref = xmldoc.CreateElement("ref");
   GovtSenderHMRCref.InnerText = strref ;
   GovtSenderClaim.AppendChild(GovtSenderref);
  
   XmlElement GovtSenderRepayments = xmldoc.CreateElement("Repayment");
   while (reader.Read())
   {
    XmlElement GovtSenderAccount = xmldoc.CreateElement("Account");
    XmlElement GovtSenderDonor = xmldoc.CreateElement("Donor");
  
     XmlElement GovtSenderfore = xmldoc.CreateElement("Fore");
     GovtSenderfore.InnerText = reader["EmployeeName_first_name"].ToString();
     GovtSenderDonor.AppendChild(GovtSenderfore);
  
     GovtSenderAccount .AppendChild(GovtSenderDonor);
  
     XmlElement GovtSenderTotal = xmldoc.CreateElement("Total");
     GovtSenderTotal.InnerText = reader["Total"].ToString();
  
     GovtSenderAccount .AppendChild(GovtSenderTotal);
  
     GovtSenderRepayments.AppendChild(GovtSenderAccount );
   }
    GovtSenderClaim.AppendChild(GovtSenderRepayments);
  
  
     GovtSenderReport.AppendChild(GovtSenderClaim);
  </code></pre>
  
  <p>and the rest of the nodes to close.. </p>