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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:33:17+00:00 2026-05-11T23:33:17+00:00

I am trying to generate an xml file of a recipe database that has

  • 0

I am trying to generate an xml file of a recipe database that has recipes with ingredients as sub elements. My query is this:

select 
    1 as 'Tag'
,null as 'parent'
,replace(r.recipe_name, '/', '') as 'item!1!title!element'
,isnull(replace(r.description, '/', ''), '') as 'item!1!description!cdata'
,r.recipe_id as 'item!1!recipe_id!element'
,null as 'ingredients!2!ingredient!element'
from recipe r
union all
select
    2 as 'Tag'
    ,1 as 'parent'
    ,null as 'item!1!title!element'
    ,null as 'item!1!description!cdata'
    ,r.recipe_id as 'item!1!recipe_id!element'
    ,i.full_ingredient_txt as 'ingredients!2!ingredient!element'
from
    recipe r, ingredient i
    where r.recipe_id = i.recipe_id
order by 'item!1!recipe_id!element'
for xml explicit

which generates the following XML:

<item>
  <title>3-D Cookie Packages</title>
  <description><![CDATA[]]></description>
  <recipe_id>52576</recipe_id>
  <ingredients>
    <ingredient>Assorted candy decorations, if desired</ingredient>
  </ingredients>
  <ingredients>
    <ingredient>cup butter or margarine, softened</ingredient>
  </ingredients>
  <ingredients>
    <ingredient>cup sugar</ingredient>
  </ingredients>
</item>

What I really want is my ingredients to nest like this:

    <ingredients>
        <ingredient>Assorted candy decorations, if desired</ingredient>
        <ingredient>cup butter or margarine, softened</ingredient>
        <ingredient>cup sugar</ingredient>
    </ingredients>

I can’t use FOR XML PATH because I need the CDATA declaration in the description field, which is not supported using this method.

  • 1 1 Answer
  • 1 View
  • 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-11T23:33:18+00:00Added an answer on May 11, 2026 at 11:33 pm

    This should do it. Added additional level to hold the parent ingredients node

    select 
    1 as Tag
    ,null as Parent
    ,replace(r.recipe_name, '/', '') as 'item!1!title!element'
    ,isnull(replace(r.description, '/', ''), '') as 'item!1!description!cdata'
    ,r.recipe_id as 'item!1!recipe_id!element'
    ,null as 'ingredients!2!'
    ,null as 'ingredient!3!'
    from recipe r
    union all
      select
        2 as Tag
        ,1 as Parent
        ,null
        ,null
        ,r.recipe_id
        ,''
        ,null
    from recipe r
    union all
      select
        3 as Tag
        ,2 as Parent
        ,null
        ,null
        ,r.recipe_id
        ,null
        ,i.full_ingredient_txt
    from  
        recipe r, ingredient i
        where r.recipe_id = i.recipe_id
    order by 'item!1!recipe_id!element'
    for xml explicit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to generate a schema from this xml file: http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?rettype=xml&retmode=xml&db=nucleotide&id=AB573763 I store
I'm trying to generate an XML file. I've got some tags that repeat numerically
I have a List<Item> collection that I am trying to generate an xml file
Trying to generate XML file from returend SQL query results. The SQL query returns
I'm trying to generate a RDoc using the XML format. Here's the command that
Note, I am not trying to generate the schema for an XML file from
I'm trying to run a T4 template that opens a XML file and uses
I'm trying to generate an XML file with the my machine's hostname in some
I'm trying to use append to generate html using data from an xml file.
I am trying to generate an XML file using the data from a class,

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.