0

I am using SQL Server 2012. I have the following code

DECLARE @x xml
SET @x = '<labels defaultText = "Javascript">      
            <label text = "Asp" />      
            <label text = "Sql" />      
            <label text = "Wcf" />
          </labels>' 

I want to write xpath/xquery query to get all attributes' values named text (in this example - "AspSqlWcf").

Thanks in advance for your help.

1 Answer 1

2

Try something like this

DECLARE @x xml
SET @x = '<labels defaultText = "Javascript">      
            <label text = "Asp" />      
            <label text = "Sql" />      
            <label text = "Wcf" />
          </labels>'  
SELECT (SELECT 
C.value('@text','nvarchar(100)') 
FROM @x.nodes('labels/label') as T(C)
FOR XML PATH(''),TYPE).value('.','nvarchar(MAX)') as val
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.