title: Creating XML document using Linq to XML in C#
body: <p>I am using below mentioned code to create a XML in C# :</p>
  
  <pre><code>     XDocument xDoc = new XDocument(new XDeclaration("1.0", "UTF-16","yes"),
            new XElement("Parent",
            from childItem in childItemList
            select new XElement("Child",
                      new XElement("source",childItem.Source),
                      new XElement("target", childItem.Target)
                      )));
  </code></pre>
  
  <p>Its working fine and document is created as expected. But I want to write </p>
  
  <pre><code>    childItem.Source 
      childItem.Target
  </code></pre>
  
  <p>as attribute values  and I used following code for that :</p>
  
  <pre><code>    XDocument xDoc = new XDocument(new XDeclaration("1.0", "UTF-16","yes"),
            new XElement("Parent",
            from childItem in childItemList
            select new XElement("Child",
                    (new XAttribute("value", childItem.Source))),
                new XElement("target", 
                   (new XAttribute("value",childItem.Target)))
                 )));
  </code></pre>
  
  <p>This code also works fine, but the problem is I have multi-line text in </p>
  
  <pre><code>    childItem.Source
      childItem.Target
  </code></pre>
  
  <p>And when same is written as Inner-Text of a node, It works fine but when this is written as value of attribute the multi-line text is being converted to single line text. I want to preserve all the white-spaces and line breaks in the XML document as it is. Any help is appreciated.</p>