4

what is the best way to convert a class to a XML and vice versa?

I want to convert my class to xml for using XRule and I want to convert back it to class with early type of properties.

thanks

Arian
  • 12,795
  • 60
  • 169
  • 277
  • possible duplicate of [Easier way to serialize C# class as XML text](http://stackoverflow.com/questions/1738511/easier-way-to-serialize-c-sharp-class-as-xml-text) – sll Dec 03 '11 at 19:30

3 Answers3

5

You can use XML Serialization to easily go from a class to XML, and the reverse. This tutorial does a good job explaining how to do it, and how to finely craft the resulting XML.

wsanville
  • 36,693
  • 7
  • 74
  • 101
1

Try the XmlSerializer class: http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx

Tudor
  • 60,450
  • 12
  • 98
  • 142
  • 1
    thanks.but I don't want save my xml to file.How I can convert serialized xml to XElement? – Arian Dec 04 '11 at 05:30
1

XRule sounds like it plays a similar role as an XML Schema (I'm not familiar with it). The XML Schema Definition (xsd.exe) tool allows you to generate common language runtime classes from XML files and vice-versa. More info can be found here.

Dave M
  • 1,282
  • 1
  • 16
  • 27
  • thanks.but I don't want save my xml to file.How I can convert serialized xml to XElement? – Arian Dec 04 '11 at 05:30