We are searching for an Library which supports the marshalling and unmarshalling like JAX-B in Java, is there any state-of-the-art library to use?
-
1http://stackoverflow.com/questions/765422/jaxb-equivalent-in-c – AakashM Aug 11 '09 at 09:13
-
1I don't think this is a dupe. For what I understand from the question, I think the OP is trying to find a framework similar to JAXB an not an external tool... – bruno conde Aug 11 '09 at 09:41
3 Answers
Like Bruno said, what you're looking for is in the System.Xml.Serialization namespace, more specifically the XmlSerializer class. To serialize an object into XML, you just need to call the Serialize method, and the reverse can be done with the Deserialize method. For more information, have a look at the MSDN topic Introducing XML Serialization.
You can sometimes hit a snag when serializing to XML, if you're having trouble be sure to check out (and contribute to) this thread.

- 1
- 1

- 15,813
- 6
- 60
- 93
System.Xml.Serialization
Namespace is what you need. It can work with attributes, like Java annotations.

- 47,767
- 15
- 98
- 117
There is something like, but not quite as JAXB. The like is stated by Allon Guralnek and bruno conde. The difference is in deserializing. With the XmlSerializer you have to give a type. The type can come from a XSD file, XML Schema, which is processed by the XSD.EXE tool. The tool create a cs file with partial classes for each defined type in the XML Schema. It is convenient to use.
But you can't use the derserializer in XmlSerilaizer, when you don't have the type for valid xml. The scenario may look like this. You receive xml-formatted messages from a message queue. You may receive any of the types defined in a XML Schema. With JAXB you derserialize the xml to an object and use the getClass property to determine, which type it is. I haven't find a similar way to do that in C#.

- 151
- 2
- 10