开发者

XPATH - Extract Data from elements

开发者 https://www.devze.com 2023-01-04 15:18 出处:网络
Following is the data and Select statement to work with : declare @XMLdata xml set @XMLdata = \' <taggroup key=\"pros\" name=\"Le pour\">

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      
    ParamVal开发者_开发知识库ues.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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消