I went through at least 5 question on SE, but I must be doing something very bad out of frustration already.
I have a stored procedure that returns an XML like this:
<pmsg:Messages>
<pmsg:Message Info="blah" />
</pmsg:Messages>
I need to get the value of Info
.
DECLARE @xmlMessage XML;
EXEC procReturnsXml @xmlMessage OUTPUT;
-- returns 0 rows
WITH XMLNAMESPACES('pmsg' AS pmsg)
SELECT msgs.msg.value('@Info', 'nvarchar(max)')
FROM @xmlMessage.nodes('pmsg:Messages/pmsg:Message') msgs(msg);
-- returns NULL
WITH XMLNAMESPACES('pmsg' AS pmsg)
SELECT @xmlMessage.value('(/pmsg:Messages/pmsg:Message/@Info)[1]', 'nvarchar(max)');
-- returns NULL
WITH XMLNAMESPACES('pmsg' AS pmsg)
SELECT t.x.value('(/pmsg:Messages/pmsg:Message/@Info)[1]', 'nvarchar(max)') AS INFO
FROM @xmlMessage.nodes('/*') t(x);
Generally, I don't understand what these mean at all. Can you provide an example exactly on this case, please?
WITH XMLNAMESPACES('http://properuri' as pmsg)
it will likely work.