for-xml

CTE and FOR XML to generate nested XML

你。 提交于 2019-11-29 01:53:01
I have an adjacency list in the DB and want to deliver the data in XML format to the client through a SQL SP. I'm trying to use CTE and FOR XML but I am not getting the XML nodes to nest. FYI, this will represent a site map. The Table structure: CREATE TABLE [dbo].[PageHierarchy]( [ModuleId] [int] NOT NULL, [PageId] [int] IDENTITY(1,1) NOT NULL, [ParentPageId] [int] NULL, [PageUrl] [nvarchar](100) NULL, [PageTitle] [nvarchar](50) NOT NULL, [PageOrder] [int] NULL) and the beginnings of the CTE: ;WITH cte AS ( select * from PageHierarchy where ParentPageId is null union all select child.* from

SQL Server FOR XML Enclosing Element?

你离开我真会死。 提交于 2019-11-28 02:06:14
Using SQL Server 2008, I have a query that emits a result set using FOR XML. Right now it is a non-compliant fragment. How can I wrap my result XML in an enclosing element and then put a simple XML declaration on top with a single schema/namespace reference to make the output compliant? Thanks. It is not possible to have the xml processing instruction in a xml datatype in sql server. See Limitations of the xml Data Type This code declare @XML xml = '<?xml version="1.0"?> <root>Value</root>' select @XML Has the output <root>Value</root> You can build the xml as a string with the xml processing

SQL Server FOR XML Enclosing Element?

被刻印的时光 ゝ 提交于 2019-11-26 23:38:46
问题 Using SQL Server 2008, I have a query that emits a result set using FOR XML. Right now it is a non-compliant fragment. How can I wrap my result XML in an enclosing element and then put a simple XML declaration on top with a single schema/namespace reference to make the output compliant? Thanks. 回答1: It is not possible to have the xml processing instruction in a xml datatype in sql server. See Limitations of the xml Data Type This code declare @XML xml = '<?xml version="1.0"?> <root>Value<