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:
- Is there a technique around this particular error?
- Is there an alternative or better way to add/change a namespace on a SQL XML type?
This is in a SQL Server 2012 stored procedure.
4条答案
按热度按时间lvjbypge1#
Maybe as simple as this?
pxyaymoc2#
Best alternative I could come up with, select root subnodes and place it between
<root xmlns="http://OurNameSpace">...</root>
.Closest I got with XQuery is this:
But that selects the first subelement (eg
<el1>
) withxmlns=""
(<el1 xmlns="">
). I didn't find a way to remove that. But maybe that is good enough for you?xyhw6mcr3#
While i am still working on this, i am using
will throw the error
Cannot use 'xmlns' in the name expression of computed attribute constructor.
Reason for that is described in this article: Adding-xmlns-to-root-element
To Summarize it, xmlns shouldn't be changed in an existing XML construction because in the case of the below possible implementation from Microsoft Forum: SQL XML Namespace Issue suggesting that all existing child elements will have to changed also.
goucqfw64#
that is my solution (wildcards solution from Pass xmlnamespaces with default as variable in SQL ):