Are you asking about how to remove all space characters in the xml document? Please load it to the XmlDocument and read from OuterXml. You will get xml document in one line
var d = new Data();
var s = new XmlSerializer(d.GetType());
var sb = new StringBuilder();
var strStream = new StringWriter(sb);
s.Serialize(strStream, d);
Trace.WriteLine(sb.ToString());// formatted document
var xd = new XmlDocument();
xd.LoadXml(sb.ToString());
Trace.WriteLine(xd.OuterXml); // document without any surplus space character or linebreaks
Data is my custom class, please find it below. It does not contain any XML serialization control attributes. You can use any class instead of it.
public class Data
{
public string BIC;
public string Addressee;
public string AccountHolder;
public string Name;
public string CityHeading;
public string NationalCode;
public bool MainBIC;
public string TypeOfChange;
public DateTime validFrom;
public DateTime validTill;
public int ParticipationType;
public string Title { get; set; }
}
First trace produces well-formatted XML
<?xml version="1.0" encoding="utf-16"?>
<Data xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MainBIC>false</MainBIC>
<validFrom>0001-01-01T00:00:00</validFrom>
<validTill>0001-01-01T00:00:00</validTill>
<ParticipationType>0</ParticipationType>
</Data>
and second trace output is single line:
<?xml version="1.0" encoding="utf-16"?><Data xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><MainBIC>false</MainBIC><validFrom>0001-01-01T00:00:00</validFrom><validTill>0001-01-01T00:00:00</validTill><ParticipationType>0</ParticipationType></Data>