Please have a glance to jpaulino's article Xml Literals
Unfortunately, this useful feature doesn't work for C#. But there is a workaround to mimic this functionality.
It combines 2 characteristics:
- Well formed xml documents can use quotes or apostrophes for attributes.
- C# string literales can have newlines when using the verbatim mode (leading @).
So, we can create a
by passing the xml string to the
method. Unique condition is to be sure that attributes are not enclosed between quotes, but between apostrophes, like the following example:
XDocument bookList = XDocument.Parse(
@"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<!-- List of books and magazines -->
<book name='The Hunger's Games' author='Suzanne Doe'/>
<book name='Breaking Dawn' author='Stephenie Meyer'/>
<book name='The Last Song' author='Nicholas Sparks'/>
Whenever the quote is needed you can use the
entity, and for apostrophes use the