I have a XML column that is not generated with a namespace, meaning no xmlns attribute. Unfortunately, I cannot fix the actual problem, meaning where the XML is created.
For example:
<root>Our Content</root>
I can modify the XML data before it's returned to a particular client that expects a namespace. What I want is pretty simple:
<root xmlns="http://OurNamespace">Our Content</root>
I tried something like:
.modify('insert attribute xmlns {"ournamespace"}...
But that errors with
Cannot use 'xmlns' in the name expression.
My questions are:
This is in a SQL Server 2012 stored procedure.
Maybe as simple as this?
DECLARE @xml XML='<root>Our Content</root>';
SELECT CAST( REPLACE(CAST(@xml AS NVARCHAR(MAX)),'<root>','<root xmlns="http://OurNamespace">') AS XML)