1

I would like to be able to paste chunks of XML into my C# code.

However, the best I can do is the following, but then I have to search and replace " with "".

Is there a way to define multiline XML in C# code without having to alter the XML text like this?

 public static string GetXml1() { return @" <Customer> <FirstName status=""required"">Jim</FirstName> <LastName status=""required"">Smith</LastName> </Customer> "; } 
3
  • I assume there's a good reason that you don't use Linq to return small snippets of XML in a typesafe fashion? Commented Jan 8, 2010 at 9:25
  • you could also to replace " with ' =) Commented Jan 8, 2010 at 9:26
  • I have XML that is already generated and need to copy it into a tool to test finding diffs between it, just thought there would be a simple way to do this, if I'm not mistaken in VB.NET you are able to just define a variable to a big block of XML. Commented Jan 8, 2010 at 9:29

2 Answers 2

5

Store the XML as a string resource then retrieve the XML as using ResourceManager.

Sign up to request clarification or add additional context in comments.

1 Comment

What if we need to parse dynamic values inside xml ?
0

Not necessarily what you are askin for, but Box/Column Select might help if the lines are alligned. Just hold down the 'Alt'-key while you use the mouse to select the " you want to remove and press delete.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.