none
Best way to update OpenXml Office Documents RRS feed

  • Question

  • I'm in the process of learning about OpenXml and how to manipulate documents.  I'm seeing several different ways to handle the XML in the docuemnts and to perfrom updates, etc.

    I've seen folks use the System.Xml.XmlDocument and others use the System.Xml.Linq.XDocument to read the Parts of an OpenXml document into.  I've seen others use an Object Model format.

    Which one is preferred?  I'm having trouble understanding which one I should be using and which one I can use to actually update a property.

    I have yet to successfully update a single attribute of an OpenXml document programmatically.  How the heck do you do this stuff?

    Sunday, February 20, 2011 11:47 PM

Answers

  • Hi Sdfsda,

    Thank you for posting and we are glad to help with you.

    >>I've seen folks use the System.Xml.XmlDocument and others use the System.Xml.Linq.XDocument to read the Parts of an OpenXml document into.  I've seen others use an Object Model format. Which one is preferred? 

    As far as I know, .NET Framework has come up with different APIs to read and write XML data. If you are using .NET3.0 and lower version, you will have to use XmlDocument to process the XML data which is the classic DOM API. With .NET3.0 and higher versions, Microsoft had launched LINQ and came up with the technology LINQ to XML. For more details about them, please take a look at this article, it covers the difference using about processing XML data: http://ashishpal.com/dotnetexplored/2009/11/xmldocument-vs-linq-to-xml/

    In addition, it is recommended that you should use System.Xml.Linq.XDocument to process XML data. It is more readability and maintainability of your code and it has a good performance than System.Xml.XmlDocument. Please take a look at this article: http://www.nearinfinity.com/blogs/joe_ferner/performance_linq_to_sql_vs.html

    I hope you can learn some useful information from the articles and feel free to follow up.

    Best Regards,

     


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by sdfsda Monday, February 21, 2011 4:27 PM
    Monday, February 21, 2011 5:36 AM