XML to Database Table

  • Hi All,

    I have simple and valid XML file "tree1.xml". I need to convert this xml file into a table "tbl_tree1" in my database.

    I have replaced "<" with "(" and ">" with ")" in below xml file because of the display problem in this post.

    (tree1)

    (ID)1(/ID)

    (Name)A(/Name)

    (ParentID)0(/ParentID)

    (Age)21(/Age)

    (/tree1)

    (tree1)

    (ID)2(/ID)

    (Name)B(/Name)

    (ParentID)1(/ParentID)

    (Age)25(/Age)

    (/tree1)

    (tree1)

    (ID)3(/ID)

    (Name)C(/Name)

    (ParentID)1(/ParentID)

    (Age)25(/Age)

    (/tree1)

    All the three records () should be inserted into my table "tbl_tree1" in a Database.

    Regards,

    Bhavesh



    [font="System"]Bhavesh Patel[/font]

    http://bhaveshgpatel.wordpress.com/
  • Hi,

    I'd recommend to read through Jacob Sebastians articles "XML Workshop ..." (search for those keywords in this site).

    It covers a lot of subject on how to deal with xml data.

    I can't remember at the moment if the way to import a file into a xml variable (normally used in his examples) is easy to find.

    If not, here's an example:

    declare @xml xml

    select @xml = convert(xml,BulkColumn)

    from openrowset(bulk 'c:\yourfile.xml', single_blob) as f

    Note: the xml stuff will be displayed (almost) correct if you use xml code tags as per the IFCode shortcut list on the lefthand side of the input box when you write a post...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • anyone out there???



    [font="System"]Bhavesh Patel[/font]

    http://bhaveshgpatel.wordpress.com/
  • Yes, I'm here, waiting for some information from your side what you've found in the articles I pointed you at.

    Did you actually check the articles I mentioned?

    Maybe the people who did read your post were under the impression that you're not asking for help with a specific problem but you're requesting us to do your job... Chances for that to happen are limited. You have to show some effort, too.

    For example by doing some research first and show us what you've tried and where you got stuck...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply