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 8921359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:31:27+00:00 2026-06-15T06:31:27+00:00

I have an xml with multiple elements and attributes ( you can see an

  • 0

I have an xml with multiple elements and attributes ( you can see an example below ) and I want to make an SQL Table/Tables from it.

XML example:

<prgs>
 <prg Id="1" >
   <name>Xulescu</name>
   <type>Human</type>
   <attribs>
     <attrib>doesn't matter</attrib>
   </attribs>
   <timeZone>doesn't matter</timeZone>
   <URL>doesn't matter/</URL>

 .....
</prgs>

I need to make a table like this

ID       |      Name
-------------------------
1        |      Xulescu
......

Thank you

Another situation

What about this ?

<schedules type="tip1">
  <schedule prgsId="15361" >
     <event Id="1234" date="2012-10-05">
       <times>
         <time>01:00</time>
       </times>
     </event>
     <event Id="2345" date="2012-10-05">
       <times>
         <time>01:30</time>
       </times>
     </event>

   

The result should be a table

    ID     ScheduleID      PrgsID        showId     Date     Time
  .................................................................
   1        xxx            xxxx          1234     2012-10-05   01:00
   2        xxx            xxxx          2345     2012-10-05   01:30

ID is an autoincrement field

ScheduleID, PrgsID are FK keys

  • 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-06-15T06:31:28+00:00Added an answer on June 15, 2026 at 6:31 am

    Something like this:

    DECLARE @XmlFile XML
    
    SELECT @XmlFile = CAST(BulkColumn AS XML)
    FROM OPENROWSET (BULK 'C:\temp\sample.xml' , SINGLE_BLOB) AS XMLDATA
    
    SELECT
        ID = Prgs.value('@Id', 'int'),
        Name = Prgs.value('(name)[1]', 'varchar(50)')
    FROM 
        @XmlFile.nodes('/prgs/prg') AS XTbl(Prgs)
    

    If your file contains this XML:

    <prgs>
     <prg Id="1" >
       <name>Xulescu</name>
       <type>Human</type>
    </prg>
     <prg Id="2" >
       <name>Xulescu2</name>
       <type>Human</type>
    </prg>
    </prgs>
    

    you’ll get this output:

    ID  Name
    ------------
    1   Xulescu
    2   Xulescu2
    

    Update: for your additional scenario – how about this? (assuming you already have your XML structure in a @XML variable):

    INSERT INTO dbo.YourTable(ScheduleID, PrgsID, ShowId, [Date], [Time])
       SELECT
           Sched.value('@prgsId', 'int'),
           Sched.value('@prgsId', 'int'),
           Events.value('@Id', 'int'),
           Events.value('@date', 'date'),
           Events.value('(times/time)[1]', 'varchar(50)')
       FROM
           @XML.nodes('/schedules/schedule') AS XTbl(Sched)
       CROSS APPLY
           Sched.nodes('event') AS XTbl2(Events)
    

    Not sure how / which attribute you want in ScheduleId and PrgsId – I only see one PrgsId attribute on <schedule> …

    • 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 (on the left) and I want to create multiple
I have an XML element with multiple child elements that use the same ID.
I have a source piece of xml into which I want to insert multiple
I want to create XML document with multiple elements inside. The format should be
Possible Duplicate: Should I use Elements or Attributes in XML? I have never been
I have an XML with multiple nodes with similar data in each. I want
I have a merged xml with a root element and multiple item child elements.
I have multiple XML configs. struts.xml <struts> <include file=struts-user.xml /> <package name=baseInterceptors extends=struts-default> <interceptor
I have an XML valued column that has multiple parent nodes. I need to
I have a XML document with my data in it, multiple entries for the

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.