Skip to content

Instantly share code, notes, and snippets.

@oscarandreu
Created February 22, 2016 14:58
Show Gist options
  • Select an option

  • Save oscarandreu/f972254cbb40ed3b0bd0 to your computer and use it in GitHub Desktop.

Select an option

Save oscarandreu/f972254cbb40ed3b0bd0 to your computer and use it in GitHub Desktop.
Serialize XML without header
public static string XmlSerializeWithoutHeader<T>(T instance)
{
if (instance == null) return null;
XmlSerializer xmlSerializer = new XmlSerializer(instance.GetType());
StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb, new XmlWriterSettings() { OmitXmlDeclaration = true })) {
xmlSerializer.Serialize(writer, instance);
}
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment