tags:

views:

48

answers:

1

Following is the data and Select statement to work with :

declare @XMLdata xml
set @XMLdata = '
    <taggroup key="pros" name="Le pour">
      <tag isuseradded="false" count="1">Bonne qualité</tag>
      <tag isuseradded="false" count="1">Correspond à mes attentes</tag>
      <tag isuseradded="true" count="1">Impeccable</tag>
      <tag isuseradded="false" count="1">Prix abordable</tag>
    </taggroup>
    '
select      
    ParamValues.ID.value('(./@key)','nvarchar(max)') as TagGroupKey,
    ParamValues.ID.value('(./@name)','nvarchar(max)') as TagGroupName,
    ParamValues.ID.value('(./tag)[1]','nvarchar(max)') as TagValue,
from @XMLData.nodes('taggroup') as ParamValues(ID)

I need to extract the 4 tag values (Bonne qualité,Correspond à mes attentes,Impeccable,Prix abordable) without actually going to the tag level since that is impacting the performance.

A: 

I am not 100% sure what you are looking for, but to get all of the data under tag without the tag element itself you would use the following xpath:

./tag/text()

This (in XPATH, I am not sure about sql xml query) would return a nodeset of TEXT elements with all of the values under tag separately. So if you had 4 tag elements, there would be four separate TEXT elements.

Aaron