views:

31

answers:

1

Hello,

I am generating a XElement having this structure:

<TestNames>\r\n <Test>YA</Test>\r\n <Test>YO</Test>\r\n </TestNames>

How do I get rid of the whitespaces and \r\n in a non-hack way :)

Update:

XElement testsXmlDocument= new XElement("TestNames");           

foreach (string test in selectedTests)         
    testsXmlDocument.Add(new XElement("Test",test)); 

return testsXmlDocument.ToString();
+3  A: 

XElement provides an overload of ToString that takes an argument of type SaveOptions. One of the values of this enumeration is DisableFormatting.

If this doesn't give you enough control then you need to use the Save overload of XElement that takes an instance of XmlWriter. The output of an XmlWriter can be controlled by using XmlWriterSettings.

Note that the recommended way of creating an XmlWriter is to use the static Create method instead of constructing one directly. If you wantthe output in a string, you can use the overload that takes a StringWriter.

Phil Devaney
worked like a charme DisableFormatting!
Lisa