Quite often our app needs to import/export XML.
Of course you can use Microsoft’s LINQ to XML to query/manipulate XML, essentially a object model, lighter weight than DOM.
However, we may prefer to work with typed an entity object and we can
- read an XML and deserialize into an object.
- serialize our entity object to xml
There are many ways to achieve typed XML programming. I will list of a couple of free approaches:
- xsd.exe. This has been around for a long time and it was built by Microsoft. It uses array. It is .NET 4.0 compatible. It is part of Microsoft Windows SDKs. For example, C:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools.
- Xsd2Code is a Codeplex project. Version 3.6 supports Visual Studio 2012 Add-in support. It can use generic collections (i.e. List<ABC>)
- LinqToXsd is another Codeplex project. This creates .NET classes with better fidelity than xsd.exe.
The tools above require an XML Schema (*.xsd) file as an input in order to generate .NET classes. Ways to generate XML Schema include:
- use Visual Studio XML Editor’s menu “XML — > Create Schema”
- use xsd.exe
Note that they only infer (i.e. guess) the XML Schema based on an existing XML file. So choose a bigger/more complex XML file if you can. It would be best if you can get a XML schema file from the maker of the XML file.
For me, I like LinqToXsd and Xsd2Code. I only use Xsd.exe as a fall backup.