Change root name of an XML document

In SQL Server 2005, we can easily change the root name of an xml document. Actually we are not "changing" it, we create a new root and add all the elements of the old root under the new one.
The following is saple code to change the root from "Root" to "NewRoot":

declare @y xml,@x xml


@x=N‘<Root xmlns=""><Test>aaa</Test></Root>’;


@y=@x.query(‘declare namespace test=""; <NewRoot xmlns="">{/test:Root/test:Test}</NewRoot>’)



This entry was posted in SQL server 2005. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s