Link to home
Start Free TrialLog in
Avatar of allsolutions
allsolutionsFlag for India

asked on

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

Hi,

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?

 




Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

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.
Avatar of allsolutions

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial