So, I have got the following query that I tried to get the value between the nodes:
<oas:Base64Assertion>235fkl53</oas:Base64Assertion>
I want to extract the value 235fkl53. I tried with the following query:
declare @x xml = '
<soapenv:Header>
<oas:Security>
<oas:Base64Assertion>
<oas:Security xmlns:oas="http://example.com">
<oas:Base64Assertion>235fkl53</oas:Base64Assertion>
</oas:Security>
</oas:Base64Assertion>
</oas:Security>
</soapenv:Header>
';
select cast(@x.value('(//oas:Base64Assertion)[1]', 'nvarchar(max)') as xml).query('//value/text()') as cdata;
But I get the following error:
Msg 2229, Level 16, State 1, Line 13 XQuery [value()]: The name "oas" does not denote a namespace.
Any tips on how to achieve this?
<soapenv:Header>?//descendant axis is slow, it's better to just put the whole path in. Looks like you actually have Base64, so you can change your data type tovarbinaryand it will decode it for you. Andmaxprobably isn't necessary unless you think it will be over 8kb long. Finally you don't need to use bothvalueandquery, you can just do@x.value('(/soapenv:Header/oas:Security/oas:Base64Assertion/oas:Security/oas:Base64Assertion/text())[1]', 'varbinary(100)').