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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:31:03+00:00 2026-05-14T22:31:03+00:00

I want to export data from a table to a specifically formatted XML file.

  • 0

I want to export data from a table to a specifically formatted XML file. I am fairly new to XML files, so what I am after may be quite obvious but I just cant find what I am looking for on the net.

The format of the XML results I need are:

    <data>
        <event 
            start="May 28 2006 09:00:00 GMT"
            end="Jun 15 2006 09:00:00 GMT"
            isDuration="true"
            title="Writing Timeline documentation"
            image="http://simile.mit.edu/images/csail-logo.gif">
            A few days to write some documentation
        </event>
     </data>

My table structure is:

name VARCHAR(50),
description VARCHAR(255),
startDate DATETIME,
endDate DATETIME

(I am not too interested in the XML fields image or isDuration at this point in time).

I have tried:

SELECT [name]
           ,[description]
           ,[startDate]
           ,[endTime]

  FROM [testing].[dbo].[time_timeline]
  FOR XML RAW('event'), ROOT('data'), type

Which gives me:

<data>
    <event name="Test1" 
           description="Test 1 Description...." 
           startDate="1900-01-01T00:00:00" 
           endTime="1900-01-01T00:00:00" 
    />
    <event name="Test2" 
           description="Test 2 Description...." 
           startDate="1900-01-01T00:00:00" 
           endTime="1900-01-01T00:00:00" 
    />
</data>

What I am missing, is the description needs to be outside of the event attributes, and there needs to be a tag.

Is anyone able to point me in the correct direction, or point me to a tutorial or similar on how to accomplish this?

Thanks,

Matt

  • 1 1 Answer
  • 3 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-05-14T22:31:03+00:00Added an answer on May 14, 2026 at 10:31 pm

    This should do the job:

    SELECT
        name "event/@name"
        , startDate "event/@start"
        , description "event"
    FROM
        [testing].[dbo].[time_timeline]
    FOR XML PATH(''), ROOT('data')
    

    Things to note:

    • In order to get description as the text content of event, we have to ‘step up’ a level and use PATH(''), and specify the name event in the alias for all columns
    • All attribute-centric columns must come before all non-attribute-centric columns

    For learning this stuff (or at least getting an idea of how to do what you want), see the docs for FOR XML and just play around with your own tables and desired XML structures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to export data from Dataset or Data Table to Excel file in
I want to export data from one table into a new one with a
We have manage to export data from our mysql table into a .txt file.
i need to export data from a table to a csv. i have the
I want to export data and structure from MySQL database using PHP. I know
I am trying to export data from my MySQL database to multiple CSV files
I want to give users the functionality of export data from one WordPress plugin
When I right click on the database I want to export data from, I
I want to export numerical data from C# to Excel where the floating point
My application has a wizard with some steps used to export data. I want

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.