WmlComparerExtensions.cs 975 B

123456789101112131415161718192021222324252627
  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using System;
  4. using System.Xml.Linq;
  5. using DocumentFormat.OpenXml.Packaging;
  6. namespace OpenXmlPowerTools
  7. {
  8. public static class WmlComparerExtensions
  9. {
  10. public static XElement GetMainDocumentBody(this WordprocessingDocument wordDocument)
  11. {
  12. return wordDocument.GetMainDocumentRoot().Element(W.body) ?? throw new ArgumentException("Invalid document.");
  13. }
  14. public static XElement GetMainDocumentRoot(this WordprocessingDocument wordDocument)
  15. {
  16. return wordDocument.MainDocumentPart?.GetXElement() ?? throw new ArgumentException("Invalid document.");
  17. }
  18. public static XElement GetXElement(this OpenXmlPart part)
  19. {
  20. return part.GetXDocument()?.Root ?? throw new ArgumentException("Invalid document.");
  21. }
  22. }
  23. }