Do you know that Visual Studio already provides an option to automatically create the entire class structure based on the XML input? Let's discuss this today.
-
Published by Kunal Chowdhury
During application development, we often use XML files. To use XML files, we need XML objects; and to create the XML objects, we need to write the classes and properties based on the XML nodes/attributes, which we do manually.
Do you know that Visual Studio already provides an option to automatically create the entire class structure based on the XML input? Let's discuss this today.

There exists many developers who are still not aware of this Visual Studio tricks, and thus spend a lot of their times creating and maintaining the classes & properties require to create the XML mapping. This manual process is no doubt a time consuming process and it's also error prone.
Visual Studio 2015 and Visual Studio 2017 provides a menu item which allows you to create the entire class structure from the XML. To do this, you will first need to copy the content of the XML and navigate to Visual Studio
Let's take the following XML as input document. We will be using this XML to create the XML mapping classes automatically from Visual Studio.
<?xml version="1.0"?> <Catalog> <Book ID="BK201701" ISBN="9781787281905"> <Title>Mastering Visual Studio 2017</Title> <Author> <Name>Kunal Chowdhury</Name> <Blog URL="https://kunal-chowdhury.com"/> </Author> </Book> <Book ID="BK201802" ISBN="9781788399807"> <Title>Windows Presentation Foundation Cookbook</Title> <Author> <Name>Kunal Chowdhury</Name> <Blog URL="https://kunal-chowdhury.com"/> </Author> </Book> </Catalog>
To do this, first create a class file (

Within a moment, all your classes will be ready for you to use. Similarly, you can create classes from JSON file content using Visual Studio.
Solution Architect & Former Microsoft MVP
Kunal Chowdhury is an enterprise solution architect and former multi-year Microsoft MVP. He is the author of three technical books: Windows Presentation Foundation Development Cookbook, Mastering Visual Studio 2017, and the Mastering Visual Studio 2019.
He publishes technical articles on Kunal-Chowdhury.com.