public void ExportChanges(XmlWriter writer) { StringBuilder sb = new StringBuilder(); foreach (TabPage page in tabControl.TabPages) { IPageView view = (IPageView)page.Controls[0]; string xml = view.ExportChanges(); if (!String.IsNullOrEmpty(xml)) { sb.Append(xml); sb.Append("\r\n"); } } try { XDocument doc = XDocument.Parse(String.Format(envelopeFormat, sb.ToString())); doc.WriteTo(writer); writer.Flush(); } catch (Exception ex) { MessageBox.Show(ex.Message, Settings.Default.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }