{"id":413,"date":"2011-05-12T17:50:36","date_gmt":"2011-05-12T17:50:36","guid":{"rendered":"http:\/\/www.ericwhite.com\/home2\/bm8qcmjy\/public_html\/blog\/?p=413"},"modified":"2011-05-12T17:52:26","modified_gmt":"2011-05-12T17:52:26","slug":"search-and-replace-text-in-an-open-xml-wordprocessingml-document","status":"publish","type":"post","link":"https:\/\/www.ericwhite.com\/blog\/2011\/05\/12\/search-and-replace-text-in-an-open-xml-wordprocessingml-document\/","title":{"rendered":"Search and Replace Text in an Open XML WordprocessingML Document"},"content":{"rendered":"<p>Searching and replacing text in an Open XML WordprocessingML document is not awfully difficult, but there are a few issues that complicate the process.&#160; The text that you are searching for may span multiple runs, so the algorithm that searches for text needs to take this into account.&#160; The replacement text should have the character formatting of the first character of the string in the document that matches the search string.&#160; I\u2019ve written a <a href=\"http:\/\/openxmldeveloper.org\/archive\/2011\/05\/12\/148357.aspx\" target=\"_blank\">blog post at OpenXMLDeveloper.org<\/a> that presents the algorithm, as well as example code written using XmlDocument (Microsoft\u2019s implementation of XML DOM).&#160; In addition, I\u2019ve recorded a screen cast that explains the algorithm:<\/p>\n<div style=\"padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px\" id=\"scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:98a5d2f0-a2e5-47df-a0f8-f4b3027fc4e4\" class=\"wlWriterEditableSmartContent\">\n<div><object width=\"448\" height=\"252\"><param name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/w128hJUu3GM?hl=en&amp;hd=1\"><\/param><embed src=\"http:\/\/www.youtube.com\/v\/w128hJUu3GM?hl=en&amp;hd=1\" type=\"application\/x-shockwave-flash\" width=\"448\" height=\"252\"><\/embed><\/object><\/div>\n<div style=\"width:448px;clear:both;font-size:.8em\">Walks through an algorithm to search and replace text in an Open XML WordprocessingML document.<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Screen-cast that shows the correct algorithm for searching and replacing 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":[3,5],"tags":[],"class_list":["post-413","post","type-post","status-publish","format-standard","hentry","category-open-xml","category-wordprocessingml"],"_links":{"self":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/413","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=413"}],"version-history":[{"count":2,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":430,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions\/430"}],"wp:attachment":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}