I have an xml structure in an existing SQL Server 2005 database table with a particular namespace defined, I need to query out the XML and in the process, change the namespace prefix to become the default namespace. The old xml has the namespace defined on the root node and child nodes and I know how to replace the root easily enough, but not the child node's namespace.
Current Data:
<sg:Settings xmlns:sg="uri:mynamespace">
<sg:SomeData xmlns:sg="uri:mynamespace"/>
</sg:Settings>
Using the SQL:
WITH XMLNAMESPACES
('uri:mynamespace' as sg)
SELECT
settingsNode.query('<Settings xmlns="uri:mynamespace"> { sg:SomeData } </Settings> ')
FROM
SettingsTable CROSS APPLY
SettingsXml.nodes('/sg:Settings') T(settingsNode)
I can get the following:
<Settings xmlns="uri:mynamespace">
<sg:SomeData xmlns:sg="uri:mynamespace"/>
</Settings>
But I'm trying to get this:
<Settings xmlns="uri:mynamespace">
<SomeData/>
</Settings>
Is there a way to merge namespaces using SQL XQuery?