0

I want to map a xml file to a SQL Server table.

This is what I've done so far:

XmlTextReader reader = new XmlTextReader("navetout.xml");
XmlNodeType type;

while (reader.Read())
{
    type = reader.NodeType;

    if(type == XmlNodeType.Element)
    {
    }
}

//using Entity framework
static void writeToDatabase()
{
    BumsEntities _bums = new BumsEntities();

    _bums.Seamen.Add(new Seamen
                     {
                        PersonalIdentityNumber = "",
                        ReferedCivicRegistrationNumber = "",
                        UnregistrationReason = "",
                        UnregistrationDate = "",
                        MessageComputerComputer = "",
                        GivenNameNumber = "",
                        FirstName = "",
                        MiddleName = "",
                        LastName = "",
                        NotifyName = "",
                        NationalRegistrationDate = "",
                        NationalRegistrationCountyCode = "",
                        NationalRegistrationMunicipalityCode = "",
                        NationalRegistrationCoAddress = "",
                        NationalRegistrationDistributionAddress1 = "",
                        NationalRegistrationDistributionAddress2 = "",
                        NationalRegistrationPostCode = "",
                        NationalRegistrationCity = "",
                        NationalRegistrationNotifyDistributionAddress = "",
                        NationalRegistrationNotifyPostCode = "",
                        NationalRegistrationNotifyCity = "",
                        ForeignDistrubtionAddress1 = "",
                        ForeignDistrubtionAddress2 = "",
                        ForeignDistrubtionAddress3 = "",
                        ForeignDistrubtionCountry = "",
                        ForeignDate = "",
                        BirthCountyCode = "",
                        BirthParish = "",
                     });

    _bums.SaveChanges();
}

The code above is the database columns. What I want to be able to do is to load the xml file and insert the tags into the columns. The problem is that I don't know how to "translate" the xml tags to the database columns.. Can anyone help me out?

3
  • "_bums" "Seamen" (゜-゜) Commented Mar 31, 2016 at 9:25
  • Which language are you doing this in, btw? I suppose C#? You might wanna tag with that (and entity framework). Commented Mar 31, 2016 at 9:26
  • @G_H Seamen is the table Commented Mar 31, 2016 at 9:31

1 Answer 1

0

This is not the entire code, however should help :

XmlTextReader reader = new XmlTextReader("navetout.xml");
DataSet ds = new DataSet("XML Data");
ds.ReadXml(reader);

// Create Database Connection here

foreach(DataTable dt in ds.Tables){

//save datatable to database - You can use SqlBulkCopy

}

Saving DataTable to database

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. What connection do you mean in "//Create connection here"?
What do you mean with saving datatable to database? I want to save XML to database. How I can translate the XML-tags to database columns?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.