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,793
  • 66
  • 176
  • 300
  • 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
  • 37,158
  • 8
  • 76
  • 101
1

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

Tudor
  • 61,523
  • 12
  • 102
  • 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,302
  • 1
  • 16
  • 28
  • 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