If you want to keep line breaks in attribute values, you need to write them with symbolic links, for example.
<foo bar="Line 1. Line 2. Line3."/>
since another wise XML parser will normalize them in space, according to the XML specification http://www.w3.org/TR/xml/#AVNormalize .
[edit] If you want to avoid normalizing the attribute value, then loading the XML using the old XmlTextReader
helps:
string testXml = @"<foo bar=""Line 1. Line 2. Line 3.""/>"; XDocument test; using (XmlTextReader xtr = new XmlTextReader(new StringReader(testXml))) { xtr.Normalization = false; test = XDocument.Load(xtr); } Console.WriteLine("|{0}|", test.Root.Attribute("bar").Value);
It outputs
|Line 1. Line 2. Line 3.|
source share