| |||||||
| |||||||
|
Return to Browsing Tutorials | Email this Tutorial to a Friend | |||||||||||||||
| ||||||||||||||||
| ||||||||||||||||
|
Reader's Comments | Post a Comment |
Another very useful attribute I forgot to mention is the [XmlText] attribute. It will cause the field to become the text between an xml element. | |
-- Andrew Ma, September 25, 2002 | |
Very nice... I've been storing application setting in xml files (and the system registry) lately, but I've been doing it the hard way! Thanks for enlightening me! | |
-- Philip Lanier, September 25, 2002 | |
For application setting, you should storing your things in the .config file (ie. if you app is called myapplication.exe, the config file is called myapplication.exe.config). This way, you don't even need to do the serialization and deserialization. You can just get your settings using ConfigurationSettings.AppSettings["keyname"]. You can find more about it in the MSDN docs. It's pretty simple and straightforward. | |
-- Andrew Ma, September 25, 2002 | |
That's really cool. It will save me tons of time and headaches, thanks. | |
-- Brent Bishop, September 27, 2002 | |
And one should never be storing their application settings in the registry with .NET applications: let the past go, man! :-) | |
-- Heath Stewart, September 29, 2002 | |
Great syntax very helpful, saves me time from figuring it out. | |
-- Sean Fitzgerald, October 01, 2002 | |
Good example, but there's a small error in the Item class definition: public class Item { [XmlAttribute("name")] public string name; [XmlAttribute("price")] public double price; ... public Item( string Name, string Price ) { should be public Item( string Name, double Price ) { No big deal, but thought it was worth bringing up if anyone wanted to try the code through copy and paste... | |
-- Ben Andrews, October 04, 2002 | |
Thanks Andrew, exactly what I was looking for. | |
-- Luke Walker, April 19, 2003 | |
I think that the tip section in the article might be partially wrong. I have ArrayList which is automatically serialized. Though I have to define the element type. [XmlElement("party", typeof(Party))] public ArrayList parties = new ArrayList(); | |
-- N S, July 03, 2003 | |
i know its not related w this subject, but happened when trying to run this example. when executing the line: TextWriter w = new StreamWriter( @"c:\\list.xml" ); i get an exception: An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll Additional information: Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed. what is nonsense to me, since ASPNET user have full access to C:\... | |
-- Daniel Marreco, August 01, 2003 | |
Very nice information.. Daniel.. as for your problem, I'm not exactly sure what the problem is, but I noticed this.. @"c:\\list.xml" the @ sign means that the text is literal and doesn't have to be escaped. which means you can use @"C:\list.xml" and it should work fine. If you want to do it the old way with "c:\\list.xml" then leave off the @ sign. | |
-- Drakier Dominaeus, August 27, 2003 | |
More useful would be to continue the code to the logical endng of deserialization and showing the data was recovered by printing it to the console..... Educational non-the-less! | |
-- Henry VanderLeest, October 30, 2006 | |
Though I can't live without XML serialization now, I really don't like XSD.exe. I've been using http://www.bonesoft.com/SkeletonCrew/Default.aspx for a while now, which produces C# or VB (among other outputs) from sample XML or XSD (among other inputs). The code it produces is much cleaner and is customizable. | |
-- Bone Head, July 06, 2007 |
1 comment:
Check the map
Post a Comment