Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

Removing the default root attributes when serializing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Newton-King - 26 Oct 2003 14:29 GMT
In an application I'm making I've got a config object which I would like to
serialize to the XML format in a .config file which would then be loaded the
next time the application starts up using Configuration class. I've got all
the elements and attributes correctly named but the default namespaces that
get added when an object is serialized are causing the program to crash when
it loads the .config file.

These are the attributes I mean -
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

I know there are easier ways of doing this but I'd like to see if I can get
it working this way.

Thanks

James
Dino Chiesa [Microsoft] - 28 Oct 2003 20:37 GMT
This is a FAQ.

To remove the default namespaces, add a namespace "" pointing to "" to the
XmlSerializerNamespaces:

   System.Xml.Serialization.XmlSerializer s = new
System.Xml.Serialization.XmlSerializer(typeof(MyType));
   MyType  x= new MyType();

   System.Xml.Serialization.XmlSerializerNamespaces ns = new
System.Xml.Serialization.XmlSerializerNamespaces();
   ns.Add( "", "" );

   s.Serialize(System.Console.Out, x, ns);  // serialize self to
Console.Out

-Dino
Signature

Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m

> In an application I'm making I've got a config object which I would like to
> serialize to the XML format in a .config file which would then be loaded the
[quoted text clipped - 13 lines]
>
> James

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.