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

  • SEARCH
  • Home
  • 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
  • 1 View
  • 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 this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have to load XML from external domain, so my code looks like this
I currently have an iPhone app that reads data from an external XML file
I have a input file Main.xml <?xml version=1.0 encoding=utf-8 ?> <Employees> <Employee> <id name=id>1</id>
I have a script that loads info from external XML file and inserts it
I have an XML document generated from an external application, but that application does
I have an external xml file that I am loading in my views.py file
We have XML generated from an external program that needs to be read into
I'm parsing an XML file from an external source, and I have 2 attributes
I have a situation where I receive an XML (document) file from an external

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.