Application type: WinConsole
I have a data import process that logs results to an XML file using an XmlTextWriter.
For each item to be imported the process creates an instance of a class, let's call it "ConfigDetail". The process calls a data insert method passing in this instance. The call to the insert method is wrapped in a try/catch. If the insert fails due to a sql error I catch the error and log the offending data to the XML file. To do this I use this code (where '_xmlWriter' is the open xml writer thats logging all results and 'config' is the offending object):
XmlSerializer objXS = new XmlSerializer(config.GetType());
This in itself works fine. However, the resulting node of XML in the file includes xmlns attributes in it which doesn't seem right. Here's an example of what I'm seeing in the context of a complete log file:
<?xml version="1.0" encoding="us-ascii"?>
<ParseReport datetime="10/15/2007 10:45:27 AM">
All of the rest of the XML is fine. It's just the namespaces in the 'ConfigDetail' element (the serialized object's root element) that seem out of place.
I have searched online and looked at the properties on the serializer but can't find anything that eliminates these attributes. I also tried several of the XmlSerializer constructors. There is a constructor overload that takes an XmlRootAttribute class but several tests with that resulted in no change.
I would have expected that because the object's XML is being added to an open XmlTextWriter that this wouldn't happen, but obviously that is not the case.
Anyone have any ideas?