Hi,
I think you are not aware of XML parsing.As you have not specified whether you want parse xml to c# and move to DB or move the data directly to DB.I have created a basic example to help you with the xml for your understanding in C# as others have given you details for moving xml to sql.Basically what it does is it will loop through all the elements in your xml under the root
<allowancededuction></allowancededuction>
. In each of the elements there are lot of attributes and each one we will loop through and get all the values and move it to a entity DataEntity. So now you can pass this DataEntity to you DataAccess Layer and insert into your DB.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ParseXML();
Console.Read();
}
public static void ParseXML()
{
string filePath=@"C:\File\Document1.xml";
XDocument XMLDocument = XDocument.Load(filePath);
List<dataentity> lstDataEntity = new List<dataentity>();
foreach (XElement ele in XMLDocument.Root.Elements())
{
DataEntity de = new DataEntity();
if (ele.Name == "allowance")
{
foreach (XAttribute attr in ele.Attributes())
{
if (attr.Name == "Name")
{
de.AllowanceName = attr.Value;
}
else if (attr.Name == "Amount")
{
de.AllowanceAmount = attr.Value;
}
}
}
else if (ele.Name == "Deduction")
{
foreach (XAttribute attr in ele.Attributes())
{
if (attr.Name == "Name")
{
de.DeductionName = attr.Value;
}
else if (attr.Name == "Amount")
{
de.DeductionName = attr.Value;
}
}
}
Console.WriteLine("AllowanceName :" + de.AllowanceName + " AllowanceAmount:" + de.AllowanceAmount + " DeductionName: " + de.DeductionName + " DeductionAmount:" + de.DeductionAmount);
lstDataEntity.Add(de);
}
}
}
public class DataEntity
{
private string allowanceName;
public string AllowanceName
{
get { return allowanceName; }
set { allowanceName = value; }
}
private string allowanceAmount;
public string AllowanceAmount
{
get { return allowanceAmount; }
set { allowanceAmount = value; }
}
private string deductionName;
public string DeductionName
{
get { return deductionName; }
set { deductionName = value; }
}
private string deductionAmount;
public string DeductionAmount
{
get { return deductionAmount; }
set { deductionAmount = value; }
}
}
}