public static class XDocumentExtensions

{

/// <summary>

/// Saves the contents of an XDocument object into a XmlDocument object

/// </summary>

/// <param name="xDocument">Source document</param>

/// <returns>Destination document</returns>

public static XmlDocument GetXmlDocument(this XDocument xDocument)

{

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.Load(xDocument.CreateReader());

return xmlDocument;

}

}

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Linq.Expressions;

using System.Xml;

using System.Xml.Linq;

using DocumentFormat.OpenXml;

using DocumentFormat.OpenXml.Packaging;

using System.Text;

using System.IO.Packaging;

using DocumentFormat.OpenXml.Wordprocessing;

 

 

/// <summary>

/// DocumentExtensions contains functions to manage the creation, reading and writing of XDocument objects

/// that come from an OpenXmlPackage

/// </summary>

public static class DocumentExtensions

{

public static void RemovePageBreaks(this Document document)

{

List<Break> breaks = document.Descendants<Break>().ToList();

foreach (Break b in breaks)

{

b.Remove();

}

document.Save();

}

public static void RemoveSectionBreaks(this Document document)

{

List<ParagraphProperties> paraProps = document.Descendants<ParagraphProperties>()

.Where(pPr => ParagraphPropertiesExtensions.IsSectionProps(pPr)).ToList();

foreach (ParagraphProperties pPr in paraProps)

{

pPr.RemoveChild<SectionProperties>(pPr.GetFirstChild<SectionProperties>());

}

document.Save();

}