I am using OpenXML and PowerTools for Open XML to process MSWord document both for custom transformation (to HTML) and for in-place modification (e.g. create style catalog).
I am having troubles understanding when one would use MainDocumentPart.GetXDocument XML navigation approach (used by PowerTools) and MainDocumentPart.Document (seem to be official examples).
I used LINQ on XDocument, but it seems you can use it for both. The MainDocumentPart.Document approach seems a bit more typed.
Is there some sort of strong conceptual difference I am missing? Things I can do in one but not in another? Inherent limitations?
With the MainDocumentPart.GetXDocument XML it is basically the same as doing XDocument.Load(MainDocumentPart.GetStream()), you are getting back an XDocument type that you can then traverse with the namespace and the node name. The MainDocumentPart.Document give you a strongly typed object that you can that has appropriate properties and accounts for differences in object locations. The nice part about the latter is that it has enumerations and type checking built in so you don't mangle a document. I am a fan of the typed model, BUT keep in mind there are some parts of the package CustomXML being an example that isn't covered in this object model and you have to use XDocument for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With