Advertisement
blowdart

Removing xsi/xsd namespaces in .NET XML Serialization

Jun 20th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. // Cull all the namespaces.
  2. // You may want to add your own here though, so replace .Add with .Add("prefix", "namespace");
  3. var namespaces = new XmlSerializerNamespaces();                    
  4. namespaces.Add(string.Empty, string.Empty);
  5.  
  6. // While we're at it, that XML version declaration can go to hell too.
  7. var settings = new XmlWriterSettings { OmitXmlDeclaration = true };
  8. var serializer = new XmlSerializer(dataType);
  9. using (var memoryStream = new MemoryStream())
  10. {
  11.     using (var writer = XmlWriter.Create(memoryStream, settings))
  12.         {
  13.             serializer.Serialize(writer, this.Data, namespaces);
  14.                 // And do whatever you want with writer at this point.
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement