How to select the value of the xsi:type attribute in SQL Server?
- by kralizek
Considering this xml document:
DECLARE @X XML (DOCUMENT search.SearchParameters) = '< parameters xmlns="http://www.educations.com/Search/Parameters.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
< parameter xsi:type="category" categoryID="38" />
< /parameters>';
I'd like to access the value of the attribute "type".
According to this blog post, the xsi:type attribute is special and can't be accessed by usal keywords/functions.
How can I do it?
PS: I tried with
WITH XMLNAMESPACES (
'http://www.educations.com/Search/Parameters.xsd' as p,
'http://www.w3.org/2001/XMLSchema-instance' as xsi
)
SELECT @X.value('(/p:parameters/p:parameter/@xsi:type)[1]','nvarchar(max)')
but it didn't work.