Is there an equivalent library for JAXB in .NET? I am trying to convert an XML I get to a .NET class. I have the XSD, but not sure how to convert the XML received into a concrete Class? I used the XSD tool to generate a class from the schema, but what I want to to convert the XML I receive on the fly to a object that I can work with in code.
I've seen the thread here that deals with this, but my query is - I want the object created to contain the data that I receive in the XML (i.e. the field values must be populated).
You can use xsd.exe to generate the class and then use XmlSerializer
in your code to populate the class. For example if xsd.exe creates a class called Foo
you could write:
Foo someFoo;
using (var stream = new FileStream("foo.xml", FileMode.Open))
{
var serializer = new XmlSerializer(typeof(Foo));
someFoo = serializer.Deserialize(stream);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With