I am trying to find an article I read about a month ago. I the article the author talk about using the XML classes in .net to map xml with a schema to POCO objects and also showed how to create a schema straight from the objects that he had. This is exactly what I'm trying to do know, but all I seem to be able to find is articles talking about manually walking through the xml and extracting the values for your objects.
I know I can manually spin through the XML to get my objects, but I have several different objects I need to map, so I'd rather go down the automated route if there is one. Does anyone know how to build a schema from a .net object and then map XML files to it with some .net automagic?
The xsd.exe
command-line utility is your friend!
See the MSDN docs for details on how to use it and what you can do with it.
In brief:
It can take a .NET assembly and generate XSD schema for each of the classes, or it can take an existing XML file and generate a XSD schema from it (as good as it can guess it), and then a C# or VB.NET class from that schema that allows you to easily deserialize a XML file into a .NET object directly.
There's also Xsd2Code - a Visual Studio (at least 2008 - not sure about 2010) plugin that allows you to have a XSD file in your project, and create a C# class from it in the Solution Explorer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.