I have a XML column in a SQL Server database. I want to get results from that column. Here is what the XML column looks like:
<ArrayOfTarget xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/TriTech.InformRMS.Domain.Core.ComplexTypes">
<Target>
<AgencyId i:nil="true" />
<AgencyName i:nil="true" />
<Id i:nil="true" />
<Name>Quick Search</Name>
<Type>Search</Type>
</Target>
<Target>
<AgencyId i:nil="true" />
<AgencyName i:nil="true" />
<Id i:nil="true" />
<Name>Quick Search = wbinc2000125</Name>
<Type>Quick Search</Type>
</Target>
<Target>
<AgencyId i:nil="true" />
<AgencyName i:nil="true" />
<Id i:nil="true" />
<Name>Results (0)</Name>
<Type>Result</Type>
</Target>
</ArrayOfTarget>
Here are some things I have tried but no results:
select
[XML].value ('(ArrayofTarget/Target/Name/node())[1]', 'nvarchar(max)') as Results
from
[DB].[dbo].[Table]
Another example:
;WITH XMLNAMESPACES (N'http://www.w3.org/2001/XMLSchema-instance' as X)
SELECT
[XML].value('(/X:ArrayOfTarget/X:Target/X:Name[1]', 'nvarchar(max)') as Name
FROM [DB].[dbo].[Table]
WITH XMLNAMESPACES, but the relevant namespace is the default namespace mentioned inxmlns(http://schemas.datacontract.org/2004/07/TriTech.InformRMS.Domain.Core.ComplexTypes). You can useDEFAULTfor that.