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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:39:54+00:00 2026-05-23T08:39:54+00:00

I need to generate the XML from the SQL Server 2008 R2 using ‘For

  • 0

I need to generate the XML from the SQL Server 2008 R2 using ‘For XML explicit’ and CDATA directive. The output should be like following:-

<?xml version="1.0" encoding="utf-8" ?>
<JOB>
<AD>
 <ID><![CDATA[ 451 ]]></ID>
 <TITLE><![CDATA[ Receptionist ]]></TITLE>
</AD>
<AD>
 <ID><![CDATA[ 1025 ]]></ID>
 <TITLE><![CDATA[ Secretary ]]></TITLE>
</AD>
</JOB>

While, the schema of table is,

Table Name : AD
Column1    : ID
Column2    : TITLE

But, I am unable to achieve this and stuck somewhere.

Many thanks.

  • 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-05-23T08:39:54+00:00Added an answer on May 23, 2026 at 8:39 am
    declare @T table(ID int, TITLE varchar(50))
    insert into @T values(451, 'Receptionist')
    insert into @T values(1025, 'Secretary')
    
    select 1    as Tag,
           null as Parent,
           ID as [AD!1!ID!CDATA],
           TITLE as [AD!1!TITLE!CDATA]
    from @T       
    order by [AD!1!ID!CDATA]
    for xml explicit  
    

    Result:

    <AD>
      <ID><![CDATA[451]]></ID>
      <TITLE><![CDATA[Receptionist]]></TITLE>
    </AD>
    <AD>
      <ID><![CDATA[1025]]></ID>
      <TITLE><![CDATA[Secretary]]></TITLE>
    </AD>
    

    Edit:
    With root node:

    declare @T table(ID int, TITLE varchar(50))
    insert into @T values(451, 'Receptionist')
    insert into @T values(1025, 'Secretary')
    
    select 1    as Tag,
           null as Parent,
           null as [JOB!1],
           null as [AD!2!ID!CDATA],
           null as [AD!2!TITLE!CDATA]
    union all
    select 2    as Tag,
           1 as Parent,
           null,
           ID,
           TITLE
    from @T 
    order by Tag, [AD!2!ID!CDATA]       
    for xml explicit       
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ActiveSupport's to_xml to generate some xml from a hash. I have need
I'm using openldap on Mac OS X Server 10.6 and need to generate a
I need to generate classes from xml that doesn't provide a schema. I understand
I need to generate xml file from controller after I find in google and
I have a need to generate XML documents from C++. For reasons of performance
I am trying to generate an XML document using the XML features in SQL
I'm completely new to Oracle's XDB, in particular using it to generate XML output
I need to convert HTML documents (generated from DocBook XML documents) to the Wiki
I'm working in a .net application where we need to generate XML files on
I need to generate an XML file in C#. I want to write the

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.