public void Replace_MultipleSearchStrings_WillReplaceAll() { List <string> searchStrings = new List <string>() { "a", "b" }; List <string> replaceStrings = new List <string>() { "abra", "babra" }; string xml = @"<Library> <Book>a</Book> <Book>b</Book> </Library>"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); _Replacer = new XmlSearchReplace(SearchReplaceLocationOptions.ReplaceElementValue, SearchReplaceOperationOptions.WholeWordOnly, searchStrings, replaceStrings); XmlDocument actualDoc = _Replacer.Replace(xmlDoc); XmlNodeList nodes = actualDoc.GetElementsByTagName("Book"); Assert.AreEqual(2, nodes.Count); Assert.AreEqual("abra", nodes[0].InnerText); Assert.AreEqual("babra", nodes[1].InnerText); }
public SearchReplaceFileReplacer(ISearchReplaceParameter parameters) { _Replacer = new XmlSearchReplace( parameters.GetLocationOptions() , parameters.GetOperationOptions() , parameters.GetSearchString() , parameters.GetReplaceString()); this._Parameters = parameters; _Document = new XmlDocument(); }
private void InitializeReplacer(string xml, SearchReplaceLocationOptions options, string searchString, string replaceString, bool wholeWordOnly, bool caseInsensitive) { _Document.LoadXml(xml); SearchReplaceOperationOptions opOptions = SearchReplaceOperationOptions.CaseSensitivePartialWord; if (wholeWordOnly) { opOptions |= SearchReplaceOperationOptions.WholeWordOnly; } if (caseInsensitive) { opOptions |= SearchReplaceOperationOptions.CaseInsensitive; } _Replacer = new XmlSearchReplace(options, opOptions, new List <string>() { searchString }, new List <string>() { replaceString }); }