There are few steps to convert XML to .Net classes. These are:
1. Copy your XML content from any file.
2. In Visual studio, open the file where you have to create classes in .Net
3. Place the cursor in that position, Go to menu bar->select EDIT-> Select Paste Special->Select Paste XML as Classes.
Example:
We have a below XML:
<?xml version="1.0"?>
<EmployeeDetails>
<FirstName>Mona</FirstName>
<LastName>Jain</LastName>
<Age>25</Age>
<EmailId>test@test.com</EmailId>
<City>Delhi</City>
<Country>India</Country>
</EmployeeDetails>
To Convert this XML into .net classes follow these steps:
1. Copy this XML
2. Paste this XML in Visual Studio file as "Paste XML as Classes" then you get "EmployeeDetails" class automatically :
Here, below is the code that will generated automatically .
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class EmployeeDetails
{
private string firstNameField;
private string lastNameField;
private byte ageField;
private string emailIdField;
private string cityField;
private string countryField;
/// <remarks/>
public string FirstName
{
get
{
return this.firstNameField;
}
set
{
this.firstNameField = value;
}
}
/// <remarks/>
public string LastName
{
get
{
return this.lastNameField;
}
set
{
this.lastNameField = value;
}
}
/// <remarks/>
public byte Age
{
get
{
return this.ageField;
}
set
{
this.ageField = value;
}
}
/// <remarks/>
public string EmailId
{
get
{
return this.emailIdField;
}
set
{
this.emailIdField = value;
}
}
/// <remarks/>
public string City
{
get
{
return this.cityField;
}
set
{
this.cityField = value;
}
}
/// <remarks/>
public string Country
{
get
{
return this.countryField;
}
set
{
this.countryField = value;
}
}
}
This feature is only available in .NET 4.5 framework in VS2012(or newer).
Thanks
0 Comment(s)