Use the following code to get rid of the XML declaration and the
namespace declaration attributes (the latter has been suggested above
already) - explicit settings for the writer do the trick:
// source: source object instance to serialize
// target: target file name to write the XML to
void Serialize(object source, string file)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.Indent = true;
using (XmlWriter writer = XmlWriter.Create(file, settings))
{
XmlSerializer serializer = new XmlSerializer(source.GetType());
XmlSerializerNamespaces namespaces = new
XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
serializer.Serialize(writer, source, namespaces);
}
}
*** Sent via Developersdex
http://www.developersdex.com ***