Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 566001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:55:55+00:00 2026-05-13T12:55:55+00:00

I have an xml file from an external system that looks like this. <?xml

  • 0

I have an xml file from an external system that looks like this.

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <Element1>
            <Element2 day="2009-10-18">
                <Element3 name="Joe">
                    <Element4 time="1">
                        <Element5 amount="0" price="16.58"/>
                    </Element4>
                </Element3>
                <Element3 name="Fred">
                    <Element4 time="5">
                        <Element5 amount="0" price="15.41"/>
                    </Element4>
                </Element3>
            </Element2>
        </Element1>
    </Body>
</Envelope>

I need to flatten this and put it into a sql table that will look like this.

day, name, time, amount, price
2009-10-18, Joe, 1, 0, 16.58
2009-10-18, Fred, 5, 0, 15.41

What is the best way to read the xml and insert it into my DB? I’ve been playing with linq but without much sucess thus far.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:55:55+00:00Added an answer on May 13, 2026 at 12:55 pm

    This article is a good starting point for the basic idea.

    Extracting XML and Insert Bulk Data using LINQ to XML and LINQ to SQL

    Adding a bit more here for those who might be interested in a similar solution.

                XDocument doc = XDocument.Load(@"myxml.xml");
                DataContext bt = new DataContext();
    
                var docxml = from c in doc.Elements("Envelope").Elements("Body").Elements("Element1").Elements("Element2").Elements("Element3")
    
                         select new mytable()
                         {
                             MyKey = Guid.NewGuid(),
                             day = Convert.ToDateTime(c.Parent.Attribute("day").Value),
                             name = c.FirstAttribute.Value,
                             time = Convert.ToInt32(c.Element("Element4").FirstAttribute.Value),
                             price = Convert.ToDecimal(c.Element("Element4").Element("Element5").Attribute("price").Value),
                             amount = Convert.ToDecimal(c.Element("Element4").Element("Element5").Attribute("amount").Value)
    
                         };
    
                bt.mytable.InsertAllOnSubmit(docxml);
                bt.SubmitChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have a helper class pulling a string from an XML file. That string
I have a flash movie that loads images dynamically from an xml file. I
I have a T4 template that generates classes from an xml file. How can
I have a xsl file that is grabbing variables from xml and they seem
I have an xml file from which I am extracting html using LINQ to
I have a datetime coming back from an XML file in the format: 20080916
I have an application which extracts data from an XML file using XPath. If
I have a 2.4 MB XML file, an export from Microsoft Project (hey I'm
I have an xml file providing data for a datagrid in Flex 2 that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.