-4

I have a program in C#,and I want to use xml in it. I am very new to XML,I have a fairly large configuration data with lots of fields.I have managed to define a class based on my configuration fields,my class has lot of enums ,lists and user defined types.

Now I want to read/edit/modify/save the values in configuration,I am thinking of using an xml file. Can you give me some direction.Should I define a xml schema? What should be the design of my program? Or please suggest how to do this fast and clean through existing APIs like LINQ etc.

In a nut shell

Can you explain

How to save class with lot of fields to XML through C#? Do I need a schema? How to read it back in same class and validate through schema?

Approach should be simple and unit testable.

TRS
  • 1,947
  • 4
  • 26
  • 49
  • 1
    This question is way too open ended. Please show us some examples of what you've tried and try to limit the scope of your question to something more specific than everything in your requirements. – Simon Whitehead Aug 12 '13 at 02:21
  • Edited for you,I do have code but its not relevant to what I am asking,I have just prepared a class from a configuration data of a product, thats it.Its a simple class and I don't think it can really help you to answer. – TRS Aug 12 '13 at 02:35

1 Answers1

1

You can use the XSD.exe tool to create a schema from your XML and generate a serializable class. Then you can populate the class instance in your code and serialize it out to XML, or deserialize the XML back into a class instance. Search with a phrase something like 'serializable class with xsd.exe' and you will find plenty of tutorials.

Of course, there are newer and better ways if you just want to persist application configuration.

example

Community
  • 1
  • 1
Les Ferguson
  • 351
  • 1
  • 6
  • Thanks ,I have created a schema shcema.xsd from my initial class "MyClass" and then I have generated serializable class from schema through xsd tool.But this class is a partial class and autogenerated its name is also "MyClass".Which one I should use for xmlserialization.Should I keep only partial class in project or both. – TRS Aug 12 '13 at 06:03