Best way to search and replace substrings in large XML files
I have ~10 large XML files for my installer projects that I need to update programmatically. I'm working on my deploy app, and I need a way to automatically update the file paths listed in the XML file. Each file used by the installer projects has a build version as part of the file path, and I need to update that part of the string. This will be anywhere from ~20 replacements to 500 replacements, depending on the installer XML file.
Looking around, it appears the main way people usually do this is to read the entire file into a String variable, then run a search and replace, then load the string back into the file. Some of these files are quite large, with about 40k lines and 900k characters.
Are there any methods that are more optimal than using something like the XDocument or File class and reading them into a String?
Are there any methods that are more optimal than using something like the XDocument or File class and reading them into a String?
3 Replies
System.IO.Pipelines
1MB xml file is not a problem for xmldocument or xdocument
especially if you are able to locate the field with xpath
with XmlDocument class you should be to use xpath to create a collection of nodes, e.g.: xpath='//FileData/FullName', then update the InnerText Property for each node in the NodeList. HTH