2

I am trying to the get the value of the x:String node (L1.0.0.0) in XML below shown code sample. The XML in the sample is generated by the TFS 2010 when we queue the builds. The XML has two major nodes and Dictionary and x:String and I have tried the query similar to the other stack overflow thread and I have included that under additional research. Any one got any suggestions why my XQuery is not working?

DECLARE @XML XML;
SET @XML = '<Dictionary x:TypeArguments="x:String, x:Object" 
xmlns="clr-namespace:System.Collections.Generic;assembly=mscorlib" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">   
<x:String x:Key="GetVersion">L1.0.0.0</x:String> 
</Dictionary>'


;WITH XMLNAMESPACES(
'clr-namespace:System.Collections.Generic;assembly=mscorlib' AS a,
'http://schemas.microsoft.com/winfx/2006/xaml' AS x)

SELECT @XML.value('(/Dictionary/x:String)[1]', varchar(100)) AS BuildLabel

Additional Research Stack Overflow T-SQL, XQuery Invalid Column

How to work with multiple namespaces

Community
  • 1
  • 1
bkraider
  • 53
  • 1
  • 9

1 Answers1

4

In your query you need to prefix Dictionary with a since clr-namespace:System.Collections.Generic;assembly=mscorlib is the default namespace and Dictionary belongs to that.

;WITH XMLNAMESPACES(
'clr-namespace:System.Collections.Generic;assembly=mscorlib' AS a,
'http://schemas.microsoft.com/winfx/2006/xaml' AS x)
SELECT @XML.value('(/a:Dictionary/x:String)[1]', 'varchar(100)') AS BuildLabel

Or you can specify the namespace as default in the query.

;WITH XMLNAMESPACES('http://schemas.microsoft.com/winfx/2006/xaml' as x,
                     DEFAULT 'clr-namespace:System.Collections.Generic;assembly=mscorlib')
SELECT @XML.value('(/Dictionary/x:String)[1]', 'varchar(100)') AS BuildLabel
Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281