{"id":459,"date":"2011-08-04T17:16:44","date_gmt":"2011-08-04T17:16:44","guid":{"rendered":"http:\/\/www.ericwhite.com\/home2\/bm8qcmjy\/public_html\/blog\/?p=459"},"modified":"2011-08-04T17:19:23","modified_gmt":"2011-08-04T17:19:23","slug":"introducing-a-new-class-for-powertools-for-open-xml-textreplacer","status":"publish","type":"post","link":"https:\/\/www.ericwhite.com\/blog\/2011\/08\/04\/introducing-a-new-class-for-powertools-for-open-xml-textreplacer\/","title":{"rendered":"Introducing a new class for PowerTools for Open XML: TextReplacer"},"content":{"rendered":"<p>Recently I wrote some code that implemented <a href=\"http:\/\/openxmldeveloper.org\/home2\/bm8qcmjy\/public_html\/blog\/b\/openxmldeveloper\/archive\/2011\/05\/12\/search-and-replace-text-in-an-open-xml-wordprocessingml-document.aspx\">search-and-replace for Open XML WordprocessingML documents<\/a>.\u00a0 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#.\u00a0 Because XML DOM is standardized, translating the code to another language and another implementation of XML DOM is relatively straightforward.<\/p>\n<p>I want to introduce search-and-replace functionality in a CMDLET in <a href=\"http:\/\/powertools.codeplex.com\/\">PowerTools for Open XML<\/a>, 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.\u00a0 It was an interesting and fun project.\u00a0 The video below introduces the TextReplacer class, and compares it to the code that I presented that uses XmlDocument.\u00a0 It is an interesting comparison of imperative code (using XmlDocument) and functional code (using LINQ to XML).<\/p>\n<p>You can download the TextReplacer class from <a href=\"http:\/\/bit.ly\/qglvlj\">this blog post<\/a> (in an attachment at the bottom).<\/p>\n<div id=\"scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:89ef4775-76bd-4eda-8993-8b9ea164316e\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px; display: inline; float: none; padding: 0px;\">\n<div><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"676\" height=\"380\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"src\" value=\"http:\/\/www.youtube.com\/v\/G4s_BbGJ17E?hl=en&amp;hd=1\" \/><embed type=\"application\/x-shockwave-flash\" width=\"676\" height=\"380\" src=\"http:\/\/www.youtube.com\/v\/G4s_BbGJ17E?hl=en&amp;hd=1\"><\/embed><\/object><\/div>\n<div style=\"width: 676px; clear: both; font-size: .8em;\">Introduces TextReplacer, which is LINQ to XML code that replaces text in WordprocessingML documents.<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Screen-cast that introduces a new class, TextReplacer, which replaces text in an Open XML WordprocessingML document.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_s2mail":"","footnotes":""},"categories":[8,14,3,9,5],"tags":[],"class_list":["post-459","post","type-post","status-publish","format-standard","hentry","category-functional-programming","category-linq-to-xml","category-open-xml","category-powertools","category-wordprocessingml"],"_links":{"self":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/comments?post=459"}],"version-history":[{"count":1,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/459\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/459\/revisions\/460"}],"wp:attachment":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/media?parent=459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/categories?post=459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/tags?post=459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}