I am serialising a number of classes to an XML file using the following code
static void GetFromDBToXml()
{
var thejob = Xmltodb.Singleton.DBManager.GetSingleObject<job>("jobid", JobData.Job.Jobid);
var theparts = Xmltodb.Singleton.DBManager.GetListOfObjects<parts>("jobid", JobData.Job.Jobid);
var thesurv = Xmltodb.Singleton.DBManager.GetListOfObjects<jobsurvey>("jobid", JobData.Job.Jobid);
try
{
using (var fs = new FileStream(Path.Combine(Xmltodb.Singleton.ContentDirectory, "temp.xml"), FileMode.OpenOrCreate))
{
var xmlSerializer = new XmlSerializer(typeof(job));
xmlSerializer.Serialize(fs, thejob);
xmlSerializer = new XmlSerializer(typeof(parts));
foreach (var p in theparts)
xmlSerializer.Serialize(fs, p);
xmlSerializer = new XmlSerializer(typeof(jobsurvey));
foreach (var s in thesurv)
xmlSerializer.Serialize(fs, s);
}
}
catch (InvalidOperationException ex)
{
Console.WriteLine("Can't write the xml file : {0}--{1}", ex.Message, ex.StackTrace);
}
}
The code is being drawn directly from SQLite and written to an XML file.
While this works, at the end of each class and start of the next I'm getting the XML header added each time. In other words
</jobsurvey>
<?xml version="1.0" encoding="utf-8">
<parts xmlns:xsi="http://www.w3.org ...
Is there a way to prevent the serialiser from generating the <?xml
and xmlns:
parts for each class being serialised without having to create the file, then reparse to remove these bits I don't need?