Open XML, SharePoint, and Office
Introducing a new class for PowerTools for Open XML: TextReplacer
Recently I wrote some code that implemented search-and-replace for Open XML WordprocessingML documents. I wrote that code for an Open XML developer who needed to implement that functionality using XML DOM, although with a different language than C#. Because XML DOM is standardized, translating the code to another language and another implementation of XML DOM is relatively straightforward.
I want to introduce search-and-replace functionality in a CMDLET in PowerTools for Open XML, but I have been moving PowerTools code away from XmlDocument, so I rewrote the search-and-replace code using LINQ to XML, using a functional transform. It was an interesting and fun project. The video below introduces the TextReplacer class, and compares it to the code that I presented that uses XmlDocument. It is an interesting comparison of imperative code (using XmlDocument) and functional code (using LINQ to XML).
You can download the TextReplacer class from this blog post (in an attachment at the bottom).