Created
February 22, 2016 14:58
-
-
Save oscarandreu/f972254cbb40ed3b0bd0 to your computer and use it in GitHub Desktop.
Serialize XML without header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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