Click here to Skip to main content
15,914,452 members
Home / Discussions / C#
   

C#

 
GeneralRe: auto versioning? Pin
zecodela7-Apr-05 0:30
zecodela7-Apr-05 0:30 
GeneralICQ Client/Protocol Pin
Moon Boy5-Apr-05 17:58
Moon Boy5-Apr-05 17:58 
GeneralRe: ICQ Client/Protocol Pin
leppie5-Apr-05 19:01
leppie5-Apr-05 19:01 
GeneralRe: ICQ Client/Protocol Pin
Daniel Grunwald9-Apr-05 5:07
Daniel Grunwald9-Apr-05 5:07 
Generalposition of the printed out datagrid Pin
MJay5-Apr-05 17:07
MJay5-Apr-05 17:07 
GeneralRe: position of the printed out datagrid Pin
Anonymous5-Apr-05 22:27
Anonymous5-Apr-05 22:27 
GeneralRe: position of the printed out datagrid Pin
MJay5-Apr-05 23:02
MJay5-Apr-05 23:02 
GeneralSaving an object to a XML file Pin
Luis Alonso Ramos5-Apr-05 16:28
Luis Alonso Ramos5-Apr-05 16:28 
I´m writing a little library, where my main object MainObject contains some properties and a collection of ElementBase (abstract) objects.

I actually have two derived classes from ElementBase, each of which has properties, some common to the base class, others specific to the type.

I would like to save this MainObject to an XML with all of its elements, according to:

  • Smallest file size possible. I don´t need uncessesary properties, only the important ones (my properties, not those from base clasess)
  • Backward compatibily. I want a new version to read old version successfully and the other way around. Properties not present should be defaulted, and newer properties ignored.
  • Support for different types of ElementBase-derivatives, both existing and future.
My idea of the XML file was something like this:
<MainObject property1="x" property2="y">
  <Element type="DerivedElement1">
    <property1>value</property1>
  </element>
  <Element type="DerivedElement2">
    <OtherProperty>value</OtherProperty>
  </element>
<MainObject>
So, the first question, what do you think? is this flexible enough?

And the second question, how do I write the XML to the file? I've been checking the System.Xml namespace and there are a lot of things in there. I could use an XmlTextWriter or an XmlDocument. I saw also XmlDataDocument but I believe it is for reading/writing a DataSet to XML, am I right?

I don´t really need code samples (they sure can help) but just an pointer on what's the easiest, yet powerful enough, way of achieving what I want.

{EDIT: and of course, how would I read the file to recreate the objects? Smile | :) )

Thanks in advance,

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: Saving an object to a XML file Pin
Christian Graus5-Apr-05 16:39
protectorChristian Graus5-Apr-05 16:39 
GeneralRe: Saving an object to a XML file Pin
DavidNohejl5-Apr-05 23:23
DavidNohejl5-Apr-05 23:23 
GeneralRe: Saving an object to a XML file Pin
Luis Alonso Ramos6-Apr-05 5:45
Luis Alonso Ramos6-Apr-05 5:45 
Generalc# Move/Resize Objects Pin
elapid5-Apr-05 15:44
elapid5-Apr-05 15:44 
GeneralRe: c# Move/Resize Objects Pin
Christian Graus5-Apr-05 16:04
protectorChristian Graus5-Apr-05 16:04 
GeneralRe: c# Move/Resize Objects Pin
elapid5-Apr-05 17:25
elapid5-Apr-05 17:25 
GeneralRe: c# Move/Resize Objects Pin
Christian Graus5-Apr-05 17:31
protectorChristian Graus5-Apr-05 17:31 
GeneralRe: c# Move/Resize Objects Pin
elapid5-Apr-05 17:37
elapid5-Apr-05 17:37 
GeneralHow do I obtain the current mouse position? Pin
elapid5-Apr-05 18:19
elapid5-Apr-05 18:19 
GeneralRe: How do I obtain the current mouse position? Pin
Ashok Dhamija5-Apr-05 18:57
Ashok Dhamija5-Apr-05 18:57 
QuestionHow to set the height of text lines? Pin
welsrping5-Apr-05 15:24
welsrping5-Apr-05 15:24 
AnswerRe: How to set the height of text lines? Pin
Ashok Dhamija5-Apr-05 18:47
Ashok Dhamija5-Apr-05 18:47 
GeneralRe: How to set the height of text lines? Pin
welsrping5-Apr-05 20:40
welsrping5-Apr-05 20:40 
GeneralRe: How to set the height of text lines? Pin
leppie5-Apr-05 23:24
leppie5-Apr-05 23:24 
GeneralRe: How to set the height of text lines? Pin
Ashok Dhamija5-Apr-05 23:26
Ashok Dhamija5-Apr-05 23:26 
GeneralRe: How to set the height of text lines? Pin
welsrping6-Apr-05 14:41
welsrping6-Apr-05 14:41 
GeneralChange working directory Pin
.Sai.5-Apr-05 14:45
.Sai.5-Apr-05 14:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.