woensdag 30 juli 2008

Omit the default namespace declarations when serializing an object

If you want to omit the default namespace declaration upon serializing an object to file, i.e.

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

and

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance",

you should add a default (empty) namespace to the call to serialize the object. See below:



// Omit the standard namespaces from the output
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);

// Write the data to a the temp file using a xml writer
XmlSerializer serializer = new XmlSerializer(typeof(vodData));
using (XmlWriter writer = XmlWriter.Create(sourceFilePath, settings))
{
serializer.Serialize(writer, data, namespaces);
}
(function($){ $(document).ready(function(){ dp.SyntaxHighlighter.BloggerMode(); dp.SyntaxHighlighter.ClipboardSwf = 'http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/clipboard.swf'; dp.SyntaxHighlighter.HighlightAll('code'); }); })(jQuery);