I am write a sql code to generate xml. This is my code:
DECLARE @inner xml = '<inner>test</inner>';
WITH XMLNAMESPACES (
DEFAULT 'urn:www.agxml.org:schemas:all:4:0',
'http://www.w3.org/2001/XMLSchema-instance' AS xsi,
'http://www.w3.org/2001/XMLSchema' AS xsd
)
SELECT
@inner
FOR XML PATH('root'), TYPE
And this is what I got (line-breaks added for readability):
<root
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:www.agxml.org:schemas:all:4:0"
>
<inner xmlns="">test</inner>
</root>
You can see <inner xmlns="">test</inner>
has an extra xmlns=""
.
I tried to remove it but I can’t. Is there a way to only add xmlns to the root?
I am using ms sql server.
Thank you,
New contributor
Chunhui Ma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
0