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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:00:19+00:00 2026-05-12T06:00:19+00:00

Background: I am generating pieces of a much larger XML document (HL7 CDA documents)

  • 0

Background: I am generating pieces of a much larger XML document (HL7 CDA documents) using SQL FOR XML queries. Following convention, we need to include section comments before this XML node so that when the nodes are reassembled into the larger document, they are easier to read.

Here is a sample of the expected output:

<!-- 
********************************************************
  Past Medical History section
********************************************************
-->

<component>
    <section>
        <code code="10153-2" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC"/>
        <title>Past Medical History</title>
        <text>
            <list>
                <item>COPD - 1998</item>
                <item>Dehydration - 2001</item>
                <item>Myocardial infarction - 2003</item>
            </list>
        </text>
    </section>
</component>

Here is the SQL FOR XML statement that I have constructed to render the above XML:

SELECT     '10153-2' AS [section/code/@code], '2.16.840.1.113883.6.1' AS [section/code/@codeSystem], 'LOINC' AS [section/code/@codeSystemName], 
                      'Past Medical History' AS [section/title],
            (SELECT     [Incident] + ' - ' + [IncidentYear] as "item"
             FROM       [tblSummaryPastMedicalHistory] AS PMH
             WHERE      ([PMH].[Incident] IS NOT NULL) AND ([PMH].[PatientUnitNumber] = [PatientEncounter].[PatientUnitNumber])
             FOR XML PATH('list'), TYPE
            ) as "section/text"
FROM         tblPatientEncounter AS PatientEncounter
WHERE     (PatientEncounterNumber = 6)
FOR XML PATH('component'), TYPE

While I can insert the comments from the controlling function that reassembles these XML snippets into the main document, our goal is to have the comments be generated with the output to avoid document construction errors.

I’ve tried a few things, but am having trouble producing the comments with the SELECT statement. I’ve tried a simple string, but have not been able to get the syntax for the line breaks. Any suggestions?

  • 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-12T06:00:19+00:00Added an answer on May 12, 2026 at 6:00 am

    Example:

    SELECT [EmployeeKey]
          ,[ParentEmployeeKey]
          ,[FirstName]
          ,[LastName]
          ,[MiddleName]
          ,[DepartmentName] AS "comment()"
      FROM [AdventureWorksDW2008].[dbo].[DimEmployee]
      FOR XML PATH('Employee'),ROOT('Employees')
    

    produces:

    <Employees>
      <Employee>
        <EmployeeKey>1</EmployeeKey>
        <ParentEmployeeKey>18</ParentEmployeeKey>
        <FirstName>Guy</FirstName>
        <LastName>Gilbert</LastName>
        <MiddleName>R</MiddleName>
        <!--Production-->
      </Employee>
      <Employee>
        <EmployeeKey>2</EmployeeKey>
        <ParentEmployeeKey>7</ParentEmployeeKey>
        <FirstName>Kevin</FirstName>
        <LastName>Brown</LastName>
        <MiddleName>F</MiddleName>
        <!--Marketing-->
      </Employee>
    </Employees>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 138k
  • Answers 138k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We use the Page's RegisterStartupScript method to register initialization functions… May 12, 2026 at 7:34 am
  • Editorial Team
    Editorial Team added an answer In general, you shouldn't do this - if a type… May 12, 2026 at 7:34 am
  • Editorial Team
    Editorial Team added an answer From the Javadocs: Parameters: out - An output stream autoFlush… May 12, 2026 at 7:34 am

Related Questions

Does anyone know how to take a swf (version 7) and use the SwfLoader
I am new to Windows and Visual Studio. I have a strong background in
Background: When generating HTML content with PHP or any such thing, it is possible
I am creating a game with an ascii-like map using Java2D on Linux (like
This should be a simple question, but I haven't been able to find a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.