What's the conceptual difference in using MainDocumentPart.GetXDocument and MainDocumentPart.Document?

I am using OpenXML and PowerTools for Open XML to process an MSWord document for both custom transformation (for HTML) and in-place modification (for example, create a styles catalog).

I am having trouble understanding when you will use the XML navigation approach of MainDocumentPart.GetXDocument (used by PowerTools) and MainDocumentPart.Document (these seem to be official examples).

I've used LINQ for the XDocument, but it looks like you can use it for both. The MainDocumentPart.Document approach looks a little more typical.

Is there a strong conceptual difference that I am missing? What can I do in one but not the other? Your own limitations?

+3


source to share


1 answer


With the XML document MainDocumentPart.GetXDocument, this is basically the same as for XDocument.Load (MainDocumentPart.GetStream ()), you return an XDocument type, which can then be traversed with a namespace and node name. The MainDocumentPart.Document gives you a strongly typed object that can have appropriate properties and accounts for differences in object locations. The nice part about the latter is that it has enums and type checking built in so you don't mangle the document. I'm a fan of the typed model, but keep in mind that some parts of the CustomXML package are examples that are not covered in this object model, and you must use XDocument for.



+2


source







All Articles