C
C#4mo ago
Skadwick

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?
No description
3 Replies
Anton
Anton4mo ago
System.IO.Pipelines
Omnissiah
Omnissiah4mo ago
1MB xml file is not a problem for xmldocument or xdocument especially if you are able to locate the field with xpath
ADaly
ADaly4mo ago
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
Want results from more Discord servers?
Add your server