Use your editor
You can insert XML into a new file in Visual Studio and use regular search-and-replace expressions to fix the document.
- Escape quotes and other problematic characters
- Add
" to the beginning and end of the line and + to the end of the line.
Then you just need to go back and add the variable name at the beginning, a half-point at the end and paste it into the source code document.
From there, you can optionally reformat the source code document (to indent it) using Edit β Advanced β Format Document.
Another option here is to use shorthand literals by adding @ before the first quote. Then newlines will be supported, and you can escape the quotation marks "" instead of \" .
Rethink Your Problem
The XML files that are stored in strings are somewhat difficult to edit and destroy part of the XML point so that they are editable. To handle this, you might consider adding XML to your project.
- You can add it to your project as content and set the properties in the file to copy it to the assembly directory. Then use the appropriate
XmlDocument load-from-file methods or just File.ReadAllText .
The advantage (and potential disadvantage) is that you can edit the file after compilation. The downside is that you need to deploy the Xml file along with your assembly.
- You can add XML to your project as an embedded resource. Then you can use
Assembly.GetManifestResourceStream to get the data from the file.
The disadvantage (and potential advantage) is that you cannot edit the file after compilation. The advantage is that you do not need to deploy the Xml file along with your assembly.
Doing this makes it easier for the developer to edit the file than it would be if Xml were overflowed into a string literal.
source share