How to assign xml content to a string explicitly

mathinvalidnik picture mathinvalidnik · Jul 15, 2013 · Viewed 17.6k times · Source

Do you know how I can explicitlyt assign xml content to a string ? Example :

string myXml = "
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
"

I want to do this but with a quite bigger file.I need it because I want to use it in my Unit testing but it shows lots of errors when I am trying to paste the content between the quotes.

Answer

Sergey Berezovskiy picture Sergey Berezovskiy · Jul 15, 2013

You need to verbatim string literal (string which starts with @ symbol) with escaped quotes (i.e. use double "" instead of single "):

        string myXml = @"
<?xml version=""1.0""?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
";