Hi,
Here is the code to remove xml header
public class XmlTextWriterFormattedNoDeclaration : System.Xml.XmlTextWriter
{
public XmlTextWriterFormattedNoDeclaration(System.IO.TextWriter w): base(w)
{
Formatting = System.Xml.Formatting.Indented;
}
public override void WriteStartDocument() { } // suppress
}
Then you can serialize like this
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = new XmlSerializer(typeof(object));
StringWriter sw = new StringWriter();
XmlWriter writer = new XmlTextWriterFormattedNoDeclaration(sw);
serializer.Serialize(writer, this, ns);
No comments:
Post a Comment