How to embed multiple Xml fragments in a single resource file in C# 2005?


My application needs to work with several small Xml fragments. I want to type them verbatim, but the problem with using verbatim string literals is that I need to escape the actual quote inside Xml with another quote for compiler to understand.

On the other hand, if I want to use Xml as a resource, then for each of the several Xml fragments, I need to create a separate resource file. Ideally what I want is a mechanism where:

1. I can store all the Xml fragments in a single file, with separate name or identifier for each Xml fragment, and
2. I can type the Xml as it is without escaping quotes and I can type them in multi line with indenting for easier readability

Is there any mechanism it can be achieved?


Who is Participating?
Jacques Bourgeois (James Burger)PresidentCommented:
First copy and each chunck as an entry in the resource editor:
 Resource editorIf you put the cursor in the entry, you will see the tabulations:
You can edit from there. There is no shortcut to enter a new tabulation, but you can select one and copy and paste if you want to edit from there.
Resource editor in Edit modeIf you prefer, do a save from the resource editor and then open the .resx file in the XML Editor by right clicking on it and going Open With. Then find the entry that has been generated from the resource editor and edit it to your taste:
 XML editorThe .vb file is a class generated by the resource editor that is compiled into the application. This is the class you use later in your application to retrieve the resources. I would not touch that one.
Jacques Bourgeois (James Burger)PresidentCommented:
It is not evident at first sight, but you can have many lines in the same resource entry. There are 3 ways to do that.

You can press Shift-Enter in the resource editor to generate a line feed, and display many lines by heightening the row, just as you would do in Excel or most grids. However, I have not found a way of generating tabulations in the editor.

You can type you Xml fragment in any text editor, and then copy an paste into the resource editor. Both tabs and line feeds are kept this way.

The third way requires a little more attention on your part: edit the resource.resx file manually. You do not see it by default, but if you activate the Show All Files button at the top of the Solution Explorer, you will find the generated resource file under My Project.
allsolutionsAuthor Commented:
I can see Resource.resx file. If I double click, it opens the Resource Editor. Below it is the generated file: Resources.Designer.cs. In which section in this generated file should I put my Xml fragments? Since it is auto generated, will it retain the changes, if I open the editor and type some value directly in editor?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.