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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:48:50+00:00 2026-06-02T10:48:50+00:00

I am using SQL server 2008 and I’m quite new to writing sql. My

  • 0

I am using SQL server 2008 and I’m quite new to writing sql. My aim is to export data from a table into xml format to create a CAP xml file that can be used in our website. Currently, I’m just writing some select statements to retrieve data in the correct format. Here is the code:

select (SELECT TOP 5 [Master_Incident_Number] AS incidents
,[Jurisdiction] AS jurisdiction
,[Response_Date] AS Date
FROM [ESCAD_DW_System].[dbo].[CurrentIncidents_V] Incident 
FOR XML PATH ('area'), type ) AS Alert for xml path (''), 
ROOT ('?xml version = "1.0" encoding = "UTF-8"?') 

However, I am getting ‘invalid XML identifier’ error for ‘?’ symbol. Can anyone help?

  • 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-02T10:48:52+00:00Added an answer on June 2, 2026 at 10:48 am

    You cannot use ROOT to add an xml encoding tag. The only way to do that is to convert the xml output into varchar(max) and prepend with your encoding tag. Keep in mind though that FOR XML output is UTF-16 by default, and therefore your UTF-8 encoding is probably unnecessary. Having said that, here is a simple example that uses a UDF to convert the xml into varchar(max):

    create function gimmexml()
    returns varchar(max)
    as
    begin
        return (
            select a='some', b='xml'
            for xml path ('')           
        )
    end
    go
    
    select '<?xml version="1.0" encoding="UTF-8"?>'+dbo.gimmexml();
    

    Result:

    <?xml version="1.0" encoding="UTF-8"?><a>some</a><b>xml</b>
    

    Further reading:
    http://www.devnewsgroups.net/group/microsoft.public.sqlserver.xml/topic60022.aspx
    http://msdn.microsoft.com/en-us/library/ms345137%28v=sql.90%29.aspx

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

Sidebar

Related Questions

Using SQL Server 2008, I need to select this XML into a Table. I
I am using SQL Server 2008 and I need to select all data from
Using SQL Server 2008, is there a way to allow inserts to a table
I am using SQL Server 2008. I know if a table has no clustered
Using SQL Server 2008. Example table : CREATE table dbo.blobtest (id int primary key
using sql server 2008 I would like to take a table that has 11
Using SQL Server 2008. I have a table variable with a single column and
I'm using SQL Server 2008. The task: take an XML file and parse it
I am using SQL Server 2008 Import Export wizard to bulk import a text
I'm new to using SQL Server 2008 DB Project's in VS 2010. I found

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.