Introduction
In this article, we will create an application that will get all data from XML files from a specific directory and convert it to a C# object.
To get all XML files from a specific location we can use the Directory library provided by 'System.IO'. The other namespaces are 'System.Xml.Serialization' to serialize the XML.
I have an XML file below:
- <?xml version="1.0" encoding="UTF-8"?>
- <entry id="99" binderId="vg" definitionId="qwe" definitionName="asd" title="this is Title" exportVersion="3" docNumber="1" docLevel="1" href="google.com">
- <attribute name="_zone" type="text">abc</attribute>
- <signature>
- <creation date="2013-09-24T07:20:47">
- <principal id="1" name="admin" title="admin" emailAddress="[email protected]">admin</principal>
- </creation>
- <modification date="2013-09-24T07:24:29">
- <principal id="1" name="admin" title="admin" emailAddress="[email protected]">admin</principal>
- </modification>
- </signature>
- <attribute name="title" type="title">This is Title</attribute>
- <attribute name="description" type="description" format="1" zoneUUID="ff">This is desc.</attribute>
- <attribute name="attachFile" type="attachFiles">
- <file href="ar1.jpg" numVersions="1">ar1.jpg</file>
- <file href="ar2.jpg" numVersions="1">ar2.jpg</file>
- <file href="ar3.jpg" numVersions="1">ar3.jpg</file>
- <file href="ar4.jpg" numVersions="1">ar4.jpg</file>
- <file href="ar5.jpg" numVersions="1">ar5.jpg</file>
- </attribute>
- <workflows/>
- <settings>
- <accessControls/>
- </settings>
- </entry>
Now, we start to create a console application for transferring all data from XML files to C# objects.
Step 1 - Create a Project
After opening Visual Studio, next, we need to create an ASP.NET MVC project. For doing that, just click File - New - Project.

After choosing a project, a new dialog will pop up. In that, select Console Application and give your project the location and a name. Then, click the "Ok" button.

I create a class file like below to map all tags data to c# objects.

Join the conversation! Your thoughts help the community grow.