Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 15th, 2007, 09:54 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default Serializing object into existing XmlTextWriter

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());
    objXS.Serialize(_xmlWriter, config);
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?


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write this by xmlTextWriter yingwen XML 0 April 17th, 2007 09:40 PM
Serializing Object Graph - Assigning Object to Jag venkat.kl C# 0 August 28th, 2006 10:39 AM
Object Existing moedev Access 3 April 12th, 2006 02:48 PM
Checking for existing object Quick209 C# 1 February 14th, 2006 07:18 PM
Error Serializing an object in a web service gabrieldcr2 .NET Web Services 1 December 12th, 2005 04:41 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.