Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. XML data import to SQL

XML data import to SQL

Scheduled Pinned Locked Moved Database
questiondatabasexmltutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    milenalukic
    wrote on last edited by
    #1

    I have an XML document with parent and 3 different chile elements. Does anyone know how to get this into SQL please? Might be a silly question but it's the first time for me. :doh:

    J P 2 Replies Last reply
    0
    • M milenalukic

      I have an XML document with parent and 3 different chile elements. Does anyone know how to get this into SQL please? Might be a silly question but it's the first time for me. :doh:

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      Probably depends on what you really mean. But some possible solutions. 1. MS SQL Server (TSQL)can process XML. So write some TSQL to do it. 2. Write some C# (or Java, C++, perl, etc) which parses the XML and outputs in to import files. Then use the inport feature of the database to import it. Myself I would generally always chose 2 because I am more familar with doing it with something besides TSQL and because then I don't need to worry about impacting database performance while it runs.

      1 Reply Last reply
      0
      • M milenalukic

        I have an XML document with parent and 3 different chile elements. Does anyone know how to get this into SQL please? Might be a silly question but it's the first time for me. :doh:

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        If the XML is something like:

        <records>
        <record>
        <id>1</id>
        <name>foo</name>
        </record>
        <record>
        <id>2</id>
        <name>bar</name>
        </record>
        </records>

        and I don't yet a table for it, then my preference is to read the XML into an XmlDocument, iterate the records, iterate the children, cobble up appropriate CREATE TABLE and INSERT statements, execute the CREATE TABLE, then iterate the document again executing the INSERT for each record. I have a console application to do this.

        M 1 Reply Last reply
        0
        • P PIEBALDconsult

          If the XML is something like:

          <records>
          <record>
          <id>1</id>
          <name>foo</name>
          </record>
          <record>
          <id>2</id>
          <name>bar</name>
          </record>
          </records>

          and I don't yet a table for it, then my preference is to read the XML into an XmlDocument, iterate the records, iterate the children, cobble up appropriate CREATE TABLE and INSERT statements, execute the CREATE TABLE, then iterate the document again executing the INSERT for each record. I have a console application to do this.

          M Offline
          M Offline
          milenalukic
          wrote on last edited by
          #4

          The XML data will be put on my ftp server and I need to read the data. I have created the tables in SQL but now need to write a stored procedure to read the XML. All examples I found only use the 1 table so I still haven't managed to get the data into multiple tables. Also in the child elements there is a field that include the foreign key [/int] added to it. I suppose I could do a substring once I read the data but for now I'm still stuck.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups