Bulk Copy and reading in an xml file that uses attributes

I have found this code which demonstrates the usage of bulkcopy of one xml file to 2 database tables. I would like to know how to read in an xml file that uses attributes using the same method as below

using (SqlConnection con = new SqlConnection(cs))
{ 
    DataSet ds = new DataSet();
    ds.ReadXml(Server.MapPath("~/Data.x­ml"));
    DataTable dtDept = ds.Tables["Department"];
    DataTable dtEmp = ds.Tables["Employee"];
    con.Open();
    using (SqlBulkCopy sb = new SqlBulkCopy(con)) 
    { 
        sb.DestinationTableName = "Departments";
        sb.ColumnMappings.Add("ID", "ID");
        sb.ColumnMappings.Add("Name", "Name");
        sb.ColumnMappings.Add("Location&quo­t;, "Location");
        sb.WriteToServer(dtDept);
    } 
    using (SqlBulkCopy sb = new SqlBulkCopy(con)) 
    { 
        sb.DestinationTableName = "Employees";
        sb.ColumnMappings.Add("ID", "ID");
        sb.ColumnMappings.Add("Name", "Name");
        sb.ColumnMappings.Add("Gender"­, "Gender");
        sb.ColumnMappings.Add("DepartmentId­", "DepartmentId");
        sb.WriteToServer(dtEmp);
    }
}


Source: xml

Leave a Reply