Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 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 November 22nd, 2007, 06:43 PM
Authorized User
Join Date: Aug 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Baby_programmer Send a message via MSN to Baby_programmer Send a message via Yahoo to Baby_programmer
Default using reflection save retrived data in xml file

hi all,
Is there any way to save xml file by iteration in defined format? rather than the way i mentioned below;
            XmlDocument myDoc = new XmlDocument();
            XmlElement root = myDoc.CreateElement("Employee");
            myDoc.AppendChild(root);//root is variable got it value using reflection
            XmlElement assmNode = myDoc.CreateElement("Name");
            root.AppendChild(assmNode);//assmNode is varible too as root
Its too long and seems very strange to me... Please help.

Baby Prgrammer
Baby Prgrammer
Old November 24th, 2007, 01:49 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

You can use the XmlSerializer class to serialize an object directly to XML. The Serialize method on that class has several overloads so I would imagine you could pass in an XmlWriter instance in order to serialize many instances of the same class to a single Xml stream. Alternatively, you could put all desired class instances into an array list or generic list then serialize the list itself.

Old November 26th, 2007, 05:34 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

You could even use the XmlDocument.LoadXml method to load an xml string.

/- Sam Judson : Wrox Technical Editor -/

Similar Threads
Thread Thread Starter Forum Replies Last Post
Save database schema to XML file brettk_1 General .NET 2 September 16th, 2006 04:27 AM
save word formfields into an xml file manjugv Word VBA 0 May 1st, 2006 04:44 PM
more nodes to b retrived if change in data ali_md SQL Server 2000 0 February 2nd, 2006 08:52 AM
Can't save XMLDoc to a xml file using JScript induriprakash Javascript 2 May 13th, 2005 02:44 PM
How to save XML file using JScript/DOM in IE induriprakash XML 2 April 26th, 2005 07:37 AM

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