Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

System.Xml.Serialization Namespace is what you need. It can work with attributes, like Java annotations.

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#.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top