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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:43:02+00:00 2026-06-12T08:43:02+00:00

I have a table that contains content (like blog posts, so fairly long text)

  • 0

I have a table that contains content (like blog posts, so fairly long text) that I want to export to a xml file.

So I want it like:

<table>
  <column1>1231</column1>
  <column2>January 1, 2001</column2>
  <column3>some very long text will all types of characters in it</column3>
</table>

Is there a built in way to do this?

Basically each column will have its own element.

The content should ideally be CDATA since the content can contain any type of character potentially.

I have sql server 2008 express.

  • 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-12T08:43:03+00:00Added an answer on June 12, 2026 at 8:43 am

    From SQL Server 2005, the FOR XML clause provides a way to convert the results of an SQL query to XML.

    E.g.
    Consider a table building with Blgd, Suit, SQFT, PDate columns.

    SELECT * FROM building FOR XML AUTO
    

    will convert the contents of table to the following XML:

    <building Bldg="1" SUit="1" SQFT="1000" PDate="2012-09-24T00:00:00" />
    <building Bldg="1" SUit="1" SQFT="1500" PDate="2011-12-31T00:00:00" />
    

    If you want the columns to be elements, then

    SELECT * FROM building FOR XML AUTO, ELEMENTS
    

    would convert the contents to following XML:

    <building>
      <Bldg>1</Bldg>
      <SUit>1</SUit>
      <SQFT>1000</SQFT>
      <PDate>2012-09-24T00:00:00</PDate>
    </building>
    <building>
      <Bldg>1</Bldg>
      <SUit>1</SUit>
      <SQFT>1500</SQFT>
      <PDate>2011-12-31T00:00:00</PDate>
    </building>
    

    If you want to model your text fields as CDATA sections, then you should use the FOR XML EXPLICIT clause and define your XML schema as per the guidelines here.

    If the above Building table has a text_col column of type TEXT that should be modeled as CDATA section in the generated XML, then the SELECT query would be as follows:

    SELECT 
        1 as Tag,
        NULL as Parent,
        Bldg AS [Building!1!Bldg!ELEMENT],
        text_col AS [Building!1!!CDATA]
    FROM Building 
    WHERE text_col IS NOT NULL
    FOR XML EXPLICIT
    

    The results would be as follows:

    <Building><Bldg>1</Bldg><![CDATA[From SQL Server 2005, the FOR XML clause provides a way to convert the results of an SQL query to XML.
    
    E.g. Consider a table building with Blgd, Suit, SQFT, PDate columns.
    
    SELECT * FROM building FOR XML AUTO
    
    will convert the contents of table to the following XML:
    
    <building Bldg="1" SUit="1" SQFT="1000" PDate="2012-09-24T00:00:00" />
    <building Bldg="1" SUit="1" SQFT="1500" PDate="2011-12-31T00:00:00" />
    If you want the columns to be elements, then
    
    SELECT * FROM building FOR XML AUTO, ELEMENTS
    would convert the contents to following XML:
    
    <building>
      <Bldg>1</Bldg>
      <SUit>1</SUit>
      <SQFT>1000</SQFT>
      <PDate>2012-09-24T00:00:00</PDate>
    </building>
    <building>
      <Bldg>1</Bldg>
      <SUit>1</SUit>
      <SQFT>1500</SQFT>
      <PDate>2011-12-31T00:00:00</PDate>
    </building>]]></Building>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like the title says, I want to have a HTML table that allows its
I have a table called wp-posts with a field post-content. This field contains the
i have a php page that contains a table which i want to display
I have two tables sturctured like so: Posts Table id content Meta Table id
I have a table that contains multiple dropdown menus for a list of profile
I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have a table that contains all the data about users . Users can
I have a table that contains common entries in two columns. For Example: Column1
I have a table that contains the stock. It's legacy database and the stock
I have a table that contains a record of prioritys that links to another

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.