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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:22:41+00:00 2026-06-18T14:22:41+00:00

I have an xml file which is given as an input to a stored

  • 0

I have an xml file which is given as an input to a stored procedure in SQL Server. I have a table which has columns element name and parent id. The root element parent id is 0 the first element parent id is 1and so on. How do I achieve this?

I have several complex types in my xml

<VoyageOrderMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="voyage.xsd">
    <MessageHeader>
            <MessageId>ID</MessageId>
            <MessageDate>2009-11-01T11:42:07.414+03:00</MessageDate>
            <MessageTypeVersion>Version</MessageTypeVersion>
            <SenderId>SI</SenderId>
            <ReceiverDetails>
                <ReceiverMethod />
                <ReceiverFormat />
                <ReceiverAddress></ReceiverAddress>
                </ReceiverDetails>
    </MessageHeader>
    <VoyageOrder>
            <VoyageID>RG-FUW-001</VoyageID>
            <Amendment>4</Amendment>
            <IMO>9256200</IMO>
            <VesselName>Fuwairit</VesselName>
            <ShipMasterName />
            <OrderDate>2009-11-01T11:41:59.149+03:00</OrderDate>
            <Passage>
                <PassageNumber>1</PassageNumber>
                <PassageType>Laden</PassageType>
                <DeparturePortName>Ras Laffan</DeparturePortName>
                <DeparturePortCode>RLF</DeparturePortCode>
                <DepartureTime>2009-10-06T19:06:00.000+03:00</DepartureTime>
                <ArrivalPortName>Suez</ArrivalPortName>
                <ArrivalPortCode>SUZ</ArrivalPortCode>
                <ArrivalTime>2009-10-13T03:00:00.000+02:00</ArrivalTime>
            </Passage>

Example output

elementname parent id column
------------------------------
voyageorder   0             1
messageheader 1           2
messageid     2           3
etc

Any help is appreciated

  • 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-18T14:22:42+00:00Added an answer on June 18, 2026 at 2:22 pm

    Looks like the Edge Table Format returned by OPENXML is something you could use.

    SQL Fiddle

    MS SQL Server 2012 Schema Setup:

    Query 1:

    declare @xml xml = '
    <VoyageOrderMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="voyage.xsd">
        <MessageHeader>
                <MessageId>ID</MessageId>
                <MessageDate>2009-11-01T11:42:07.414+03:00</MessageDate>
        </MessageHeader>
        <VoyageOrder>
                <VoyageID>RG-FUW-001</VoyageID>
                <Amendment>4</Amendment>
                <OrderDate>2009-11-01T11:41:59.149+03:00</OrderDate>
                <Passage>
                    <PassageNumber>1</PassageNumber>
                    <PassageType>Laden</PassageType>
                </Passage>
        </VoyageOrder>
    </VoyageOrderMessage>'
    
    declare @idoc int
    
    exec sp_xml_preparedocument @idoc output, @xml
    
    select *
    from openxml(@idoc, '*')
    
    exec sp_xml_removedocument @idoc
    

    Results:

    | ID | PARENTID | NODETYPE |                 LOCALNAME | PREFIX |                              NAMESPACEURI | DATATYPE |   PREV |                                      TEXT |
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    |  0 |   (null) |        1 |        VoyageOrderMessage | (null) |                                    (null) |   (null) | (null) |                                    (null) |
    |  2 |        0 |        2 |                       xsi |  xmlns |                                    (null) |   (null) | (null) |                                    (null) |
    | 14 |        2 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) | http://www.w3.org/2001/XMLSchema-instance |
    |  3 |        0 |        2 | noNamespaceSchemaLocation |    xsi | http://www.w3.org/2001/XMLSchema-instance |   (null) | (null) |                                    (null) |
    | 15 |        3 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) |                                voyage.xsd |
    |  4 |        0 |        1 |             MessageHeader | (null) |                                    (null) |   (null) | (null) |                                    (null) |
    |  5 |        4 |        1 |                 MessageId | (null) |                                    (null) |   (null) | (null) |                                    (null) |
    | 16 |        5 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) |                                        ID |
    |  6 |        4 |        1 |               MessageDate | (null) |                                    (null) |   (null) |      5 |                                    (null) |
    | 17 |        6 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) |             2009-11-01T11:42:07.414+03:00 |
    |  7 |        0 |        1 |               VoyageOrder | (null) |                                    (null) |   (null) |      4 |                                    (null) |
    |  8 |        7 |        1 |                  VoyageID | (null) |                                    (null) |   (null) | (null) |                                    (null) |
    | 18 |        8 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) |                                RG-FUW-001 |
    |  9 |        7 |        1 |                 Amendment | (null) |                                    (null) |   (null) |      8 |                                    (null) |
    | 19 |        9 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) |                                         4 |
    | 10 |        7 |        1 |                 OrderDate | (null) |                                    (null) |   (null) |      9 |                                    (null) |
    | 20 |       10 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) |             2009-11-01T11:41:59.149+03:00 |
    | 11 |        7 |        1 |                   Passage | (null) |                                    (null) |   (null) |     10 |                                    (null) |
    | 12 |       11 |        1 |             PassageNumber | (null) |                                    (null) |   (null) | (null) |                                    (null) |
    | 21 |       12 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) |                                         1 |
    | 13 |       11 |        1 |               PassageType | (null) |                                    (null) |   (null) |     12 |                                    (null) |
    | 22 |       13 |        3 |                     #text | (null) |                                    (null) |   (null) | (null) |                                     Laden |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml file which has text init. i.e Hi my name is
I have written xml file which contains html tags as element like <component> <input
I have an XML file which has many section like the one below: <Operations>
I have an XML file which has to be transformed using XSLT, I am
I have to complete this task: I'm given a xml file which is exported
I have an XML-File, which has the following structure: <mediawiki ...> <siteinfo>...</siteinfo> <page> <title>The
I have been given an application which uses a build.xml file for building purposes.
I have been given an existing project which is consisting of pom.xml file in
I have a big XML file which contains some HTML <Orchard> <Recipe> <Name>Generated by
Hi I have big xml file which has a structure similar to the one

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.